Tips_sql > Postgresql > Installing PostgreSQL on Mac OS X 10.5 Leopard
I tried to install PostgreSQL on a fresh out of the box Mac Mini with Mac OS X 10.5 (Leopard) using the installations in StudioTips that I had used for installation on Mac OS X 10.4 but I couldn't get it to wouldn't work.
Apple made changes in Leopard (postgres user to a hidden user).
is gone), and PostgreSQLforMac made changes in their unified installer 8.3.0 (setting theAfter a bunch of searching and trouble shooting I managed to get the PostgreSQLforMac 8.3 universal installer to work with Mac OS X 10.5. I decided to create a new set of PostgreSQL instructions specifically for Mac OS X 10.5 and renamed the old instructions to be specifically for Mac OS X 10.4
This section covers the steps involved with installing and configuring PostgreSQL on Mac OS X 10.5 using the PostgreSQLforMac 8.3 unified installer.Get the following files off the internet and install them on your Mac OS X computer. (As of PostgreSQL 8)
Before tinkering with configuration files I suggest you test to see whether or not PostgreSQL will startup.
It's nice when things go smoothly for the installation, but sometimes they don't. The first time I tried installing PostgreSQL on a brand new Mac Mini with Mac OS X 10.5 it wouldn't start. After numerous Google searches I found some helpful advice on how to track down and solve the problem.
The following steps were taken to figure out why PostgreSQL wouldn't start up after I installed it.
You need to edit the global bash profile as follows:
export PATH=/Library/PostgreSQL8/bin:$PATH
export PGDATA=/Library/PostgreSQL8/data
You need to change the Shared Memory Settings. This is done so that you can increase the shared_buffers parameter to greater than the standard 8MB. Shared buffers allow PostgreSQL to use much more memory and can improve performance quite dramatically.
Set up a sysctl.conf file as follows:
kern.sysv.shmmax=524288000
kern.sysv.shmmin=1
kern.sysv.shmmni=64
kern.sysv.shmseg=16
kern.sysv.semmns=130
kern.sysv.shmall=131072000
kern.sysv.maxproc=2048
kern.maxprocperuid=512
shmmax is the key setting; it is in bytes. The value in this example is 500MB. If the machine has more memory to use, then this should be increased as well. shmall is the shmmax setting divided by 4.
1 MB = 1048576 bytes
This file controls all access to the PostgreSQL server. In order for clients to connect to the server their IP address must be in the allowed list of users. The two common methods that you will see being used are md5 and trust. Md5 does md5 password authentication and should be used for just about all entries to this file. Trust allows clients to connect without password authentication, the only entry trust should ever have is for the local server machine.
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.1.0/24 trust
# IPv6 local connections:
host all all ::1/128 trust
NOTE:The CIDR address as noted above has many combinations. Here is an example of the common one's you will see:
192.168.150.50 = 192.168.150.50/32
192.168.150.XXX = 192.168.150.0/24
192.168.XXX.XXX = 192.168.0.0/16
192.XXX.XXX.XXX = 192.0.0.0/8
XXX.XXX.XXX.XXX = 0.0.0.0/0 (This allows everything... probably should never use that)
Parameters that have a # character in front of them are considered not in use. If a parameter that is required has one of these in front, remove the # character before changing the setting.
The following are common properties you may want to verify/change:
1 MB = 1048576 bytes
The Applications/PostgreSQL folder is handy for starting and stopping PostgreSQL.
application which was installed in yourAfter you setup all the PostgreSQL configuration stuff you should stop and restart PostgreSQL to make check it still works.
You are now ready to create uesrs and a database and start using the database server!
The /Library/StartupItems/PostgreSQL/
universal installer sets up PostgreSQL to automatically startup when you restart the computer. The startup files can be found inTo stop and start the server from the command line:
If you like to separate the roles of superusers and tables owner users, you can create them from the command line.
With what we've done so far, postgres, is the only user, and is a superuser.
If you want to add as a different superuser, you can do so from the command line as follows
You may want to add a separate tables owner user if you want a separate role to own all the tables.
I normally create a tablesowner user by the name of dbadmin which owns all of the tables in my databases.
To drop a user:
Enter: dropuser username -P -U superusername
As of PostgreSQL 8, users and groups are internally referenced as roles. In the above steps we really created the roles of superusername and tablesownername.
Roles are global across a database cluster installation, not per database.You can use the
app to create new databases.Or you can create databases from the command line as follows:
Enter: createdb databasename -U postgresYou can use the
app to create new databases.Or you can drop databases from the command line as follows:
Enter: dropdb databasename -U postgresTo backup a database from the command line on Mac OS X:
[Database] is replaced with the database name.
[Path] is the path where you want to backup to go including the file name and extension.
For uncompressed use the file extension .sql
For compressed use the file extension .backup
Compressed backup example for the database 'Demo' as follows:
e.g For Database 'Demo' -> pg_dump -U postgres -o Demo > /Users/Shared/MyBackups/Demo.sql
To backup a database from the command line on Mac OS X:
[Database] is replaced with the database name.
[Path] is the path where you want to backup to go including the file name and extension.
Uncompressed:
e.g For Database 'Demo' -> psql Demo < /Users/Shared/MyBackups/Demo.sql
You can excecute SQL from the Terminal app command line in a database you have created:
psql databasename -U username
The username you enter will default to being the tablesowner of any tables you create.
All going well you will now be at the psql prompt:
databasename=>
From the psql prompt you can enter whatever SQL commands you like. You must end each SQL command with the ; semi-colon character.
To exit psql enter: \q
If you'd like you can enter the following series of commands from the pgsql prompt to create a table, insert a few records, and then select the records.