samedi 26 décembre 2009

Install PostgreSQL on Mac OS X

I'm using MySQL as everybody who start web development with PHP MYSQL (it's not true, i've star with Perl/CGI), but now i need some GIS features that Mysql cant do (as often with mysql... remember transaction in the 2000's), so i'm going to switch to PostgreSQL, (AkH will be happy after 10 years trying to make me switch).

Easy way to install PostgreSQL on Mac OS X with MacPorts :

make sure port db and macport is up to date :
homer:~ juju$ sudo port selfupdate

install PostgreSQL server (and client)
homer:~ juju$ sudo port install postgresql84-server

do some configuration :
homer:~ juju$ sudo mkdir -p /opt/local/var/db/postgresql84/defaultdb
homer:~ juju$ sudo chown postgres:postgres /opt/local/var/db/postgresql84/defaultdb
homer:~ juju$ sudo su postgres -c '/opt/local/lib/postgresql84/bin/initdb --encoding=UTF8 -D /opt/local/var/db/postgresql84/defaultdb'
(ou : homer:~ juju$ sudo su postgres -c '/opt/local/lib/postgresql84/bin/initdb --locale=en_US.UTF-8 --encoding=UTF8 -D /opt/local/var/db/postgresql84/defaultdb')
homer:~ juju$ sudo chown postgres:postgres /opt/local/var/db/postgresql84


set up the HOME directory for postgres user:

we can found info about the user postgres the MacPort created for us:
homer:~ juju$ sudo dscl . -read /Users/postgres
AppleMetaNodeLocation: /Local/Default
GeneratedUID: 1C1031EB-53F0-4877-984F-EA0D4C82283E
NFSHomeDirectory: /opt/local/var/db/postgresql84
Password: *
PrimaryGroupID: 500
RealName:
PostgreSQL-84 Server
RecordName: postgres
RecordType: dsRecTypeStandard:Users
UniqueID: 500
UserShell: /bin/sh


set up postgres user environment PATH var :
add this line in postgres user's .profile:
homer:~ juju$ sudo vi /opt/local/var/db/postgresql84/.profile
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql84/bin:$PATH
homer:~ juju$ sudo chown postgres:postgres /opt/local/var/db/postgresql84/.profile


this is optional : tell Os X to run postgreSQL server at boot :
homer:~ juju$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql84-server.plist

else :
start :
sudo launchctl load -F /Library/LaunchDaemons/org.macports.postgresql84-server.plist
stop :
sudo launchctl unload /Library/LaunchDaemons/org.macports.postgresql84-server.plist

to easy acces your db you can downlaod PgAdmin

Now we can create our first database.

1 commentaire:

Diab_ a dit…

Akh a pas de genou mais il a de bonnes idées ^^