Tuesday, June 7, 2011

OSX 10.7 Lion / Postgres installation issue

Recently I tried to install PostgreSQL on OSX 10.7 Lion and failed with this:

Problem running post-install step. Installation may not complete correctly
The database cluster initialisation failed.

I looked into /Library/PostgreSQL/8.3 and everything seems to be there except the data directory. So open up System Preferences > Users & Groups and add a user postgres. Then as root:

cd /Library/PostgreSQL/8.3
mkdir data
chmod 700 data
chown postgres data
su postgres
./bin/initdb /Library/PostgreSQL/8.3/data
(Watch it go and then you can start your server via)

./bin/postgres -D /Library/PostgreSQL/8.3/data
or
./bin/pg_ctl start -D /Library/PostgreSQL/8.3/data/ (for daemon mode, pg_ctl --help has a full list of commands)

Now in a new tab try /Library/PostgreSQL/8.3/bin/psql -U postgres and all should connect.

One word of warning. If you are using just psql without the full path it will load the default Lion psql command and you'll get this error:

dyld: Library not loaded: /usr/lib/libpq.5.dylib
Referenced from: /usr/bin/psql
Reason: no suitable image found. Did find:
/usr/lib/libpq.5.dylib: no matching architecture in universal wrapper
/usr/lib/libpq.5.dylib: no matching architecture in universal wrapper
Trace/BPT trap: 5

So make sure when launching psql that you include full path to the installation directory.

B