How do I set up and use a postgresql server?


The postgres daemon ordinarily runs as a nonpriveleged user, so anyone can set up and maintain a personal database tree, apart from normal limitations such as quota, available ports to bind to, etc. A brief walkthrough:

Run initdb to set up a directory for postgres to use for its config and data files, as well as a default database (template1). Simply create an empty directory and point it there. Example usage:

/usr/local/bin/initdb /homes/building/postgres

You can now start up the postgres server using your personal directory, with something like /usr/local/bin/postgres -D /homes/building/postgres. Bear in mind this must run as a nonpriveleged user (running as yourself is fine for most folks). It can also bind a tcp port by default (5432) and a unix domain socket, so multiple instances of postmaster will generally not run on the same machine without changing the port or turning this functionality (see the documentation, and the postmaster.opts or postgresql.conf file in your postgres data tree).

From here you can use the postgres console or utilities to create and drop databases as desired (createdb <dbname>, dropdb <dbname>). To interactively access the database with an SQL console, use psql <dbname>. The Perl Pg.pm module is installe in CS Solaris 8 machines, in addition to the usual C interfaces.

Be careful to limit access to your database as is necessary, for instance by only using a local unix socket instead of binding the tcp port if you don't need it. Detailed documentation for access control and general use can be found at: http://www.postgresql.org/users-lounge/index.html


Last Modified: September, 2005