New Postgres install

Before you can do anything, you must initialize a database storage area on disk. We call this a database cluster. (SQL uses the term catalog cluster.) A database cluster is a collection of databases that is managed by a single instance of a running database server. After initialization, a database cluster will contain a database named postgres, which is meant as a default database for use by utilities, users and third party applications. The database server itself does not require the postgres database to exist, but many external utility programs assume it exists. Another database created within each cluster during initialization is called template1. As the name suggests, this will be used as a template for subsequently created databases; it should not be used for actual work.

There is no default, although locations such as /usr/local/pgsql/data or /var/lib/pgsql/data are popular. To initialize a database cluster, use the command initdb, which is installed with PostgreSQL. The desired file system location of your database cluster is indicated by the -D option, for example

$ initdb -D /usr/local/pgsql/data

Note that you must execute this command while logged into the PostgreSQL user account, which is described in the previous section.

Tip: As an alternative to the -D option, you can set the environment variable PGDATA.

initdb will attempt to create the directory you specify if it does not already exist. It is likely that it will not have the permission to do so (if you followed our advice and created an unprivileged account). In that case you should create the directory yourself (as root) and change the owner to be the PostgreSQL user. Here is how this might be done:

root# mkdir /usr/local/pgsql/data
root# chown postgres /usr/local/pgsql/data
root# su postgres
postgres$ initdb -D /usr/local/pgsql/data

For Fedora 11
# su - postgres
-bash-4.0$ ls /var/lib/pgsql/data
-bash-4.0$ initdb -D /var/lib/pgsql/data

To start the database server using:

postgres -D /var/lib/pgsql/data /* note this runs the server in the forground */
or
pg_ctl -D /var/lib/pgsql/data -l logfile start /* run in background */

To Stop the database
pg_ctl -D /var/lib/pgsql/data -l logfile stop

To Create a new database (think of a database as an Oracle Instance)
-bash-4.0$ createdb mydb

Access the database
-bash-4.0$ psql mydb

If the prompt looks like mydb=> you are a regular user if like mydb=# you are the superuser.

To see the version
mydb=# select version();
version
---------------------------------------------------------------------
PostgreSQL 8.3.9 on x86_64-redhat-linux-gnu,
(1 row)

For help type:
\h

To get out of psql type

\q

Subject