Friday, November 25, 2011

Running PostgreSQL From Command Line

This October I enrolled for the online database course offered by Stanford university. I started out with SQLite as the RDBMS of my choice because it is easy to use, needs no installation and one can use it out of the box. But, in case of SQLite simplicity was the main problem too. So, I downloaded the PostgreSQL for windows. Now, as my workstation is normally overloaded (so I can’t afford background services) and also I just wanted to have a no-install distribution; so I downloaded the Zip Archive.

The first problem I faced was that when I started to run my postgres server then it gave me this long error message:
“Execution of PostgreSQL by a user with administrative permissions is not permitted.The server must be started under an unprivileged user ID to prevent possible system security compromises.  See the documentation for more information on how to properly start the server.”

Forums were of no use and mostly people were suggesting to create a non-admin user and use it. But the problem is I can’t do that as I am working a system which doesn’t allow me to do that. So, I read the documentation and found pg_ctl which is a utility to initialize, start, stop, or control a PostgreSQL server. Here are the steps:
  1. CD C:\pgsql\bin (or where ever your postgres bin folder is)
  2. set PGDATA=c:/temp/test
  3. pg_ctl.exe init
    The files belonging to this database system will be owned by user "ABCDXYZ". This user must also own the server process….
  4. Although after the step# 2 it instructs to start your postgres server as "C:/pgsql/bin\postgres" -D "c:/temp/test"; but it is of no use. Instead do this, pg_ctl.exe start
  5. That it, the server is running and the process is owned by the logged in user.
  6. Now for the admin tool, run the ‘pgAdmin3.exe’ (its inside the C:\pgsql\bin)
  7. Now select ‘Add a connection to server’ toolbar button. This will show an image like this and fill in the values as suggested:

  8. Finally this page will come: