Sunday, July 12, 2009

Initializing, Starting, Stopping, and Accessing the PostgreSQL Server on Windows

This assumes that you have the PostgreSQL binaries for Windows and that you have placed it at "c:\pgsql" directory. To set up PostgreSQL, copy the "libpq.dll" file located in the directory "c:\pgsql\lib" to the "c:\windows\system32" directory as follows:

c:\pgsql\lib> copy libpq.dll c:\windows\system32


To initialize the database, create the data directory and initialize it by issuing the "initdb" command in the "c:\pgsql\bin" directory as follows:

c:\pgsql\bin>mkdir c:\pgsql\data
c:\pgsql\bin>initdb -D "c:\pgsql\data"


To start the database, type the "pg_ctl" command as follows:

c:\pgsql\bin> pg_ctl -D "c:\pgsql\data" -l logfile start

This will start the PostgreSQL database and create the database log file "logfile".

To stop the database, type the "pg_ctl" command as follows:

c:\pgsql\bin> pg_ctl -D "c:\pgsql\data" stop

To access the database at the DOS command prompt on Windows, type the command:

c:\pgsql\bin> cmd.exe /c chcp 1252
c:\pgsql\bin> psql

No comments: