Use MacPorts install PostgreSQL server
sudo port install postgresql93-serverCreate Database Instance
sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb' sudo mkdir -p /opt/local/var/log/postgresql sudo chown postgres:postgres /opt/local/var/log/postgresqlStart Database Server
sudo su postgres -c '/opt/local/lib/postgresql93/bin/postgres -D /opt/local/var/db/postgresql93/defaultdb'or
sudo su postgres -c '/opt/local/lib/postgresql93/bin/pg_ctl -D /opt/local/var/db/postgresql93/defaultdb -l /opt/local/var/log/postgresql/postgres.log start'Set PATH environment variable
export PATH=/opt/local/lib/postgresql93/bin:$PATHMake sure you set the PostgreSQL path before /usr/bin to ensure that you are using the latest versions and not the default Apple provided, otherwise will encounter error when execute operation.
Create User
createuser --superuser Chris -U postgresCreate Database
createdb mydbIf below error encountered, that caused by you use old version PostgreSQL which provide by Apple, change PATH environment variable to solve.
createdb: could not connect to database postgres: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?Accessing Database
psql mydbmydb=# means you are a database superuser, otherwise display mydb=>.
Exit psql
mydb=> \qShutdown Database Server
sudo su postgres -c 'pg_ctl -D /opt/local/var/db/postgresql93/defaultdb -l /opt/local/var/log/postgresql/postgres.log stop'