Creating and running Postgresql on mac

I am using macports for the installation

Run

sudo port install postgresql92

and then

sudo port install postgresql92-server

Once the server has been installed, run the following

To create a database instance, after install do

 sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb
 sudo chown postgres:postgres /opt/local/var/db/postgresql92/defaultdb
 sudo su postgres -c ‘/opt/local/lib/postgresql92/bin/initdb -D /opt/local/var/db/postgresql92/defaultdb’

The output you will see

The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “en_GB.utf-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

fixing permissions on existing directory /opt/local/var/db/postgresql92/defaultdb … ok
creating subdirectories … ok
selecting default max_connections … 20
selecting default shared_buffers … 1600kB
creating configuration files … ok
creating template1 database in /opt/local/var/db/postgresql92/defaultdb/base/1 … ok
initializing pg_authid … ok
initializing dependencies … ok
creating system views … ok
loading system objects’ descriptions … ok
creating collations … ok
creating conversions … ok
creating dictionaries … ok
setting privileges on built-in objects … ok
creating information schema … ok
loading PL/pgSQL server-side language … ok
vacuuming database template1 … ok
copying template1 to template0 … ok
copying template1 to postgres … ok

WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and –auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /opt/local/lib/postgresql92/bin/postgres -D /opt/local/var/db/postgresql92/defaultdb
or
    /opt/local/lib/postgresql92/bin/pg_ctl -D /opt/local/var/db/postgresql92/defaultdb -l logfile start

Switch to the postgres id using

sudo su – postgres

Then run the following command

/opt/local/lib/postgresql92/bin/postgres -D /opt/local/var/db/postgresql92/defaultdb

The output will be

LOG:  database system was shut down at 2013-02-28 14:43:36 GMT
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

Once you run the above command as suggested, the server will be available for use