Register and run PostgreSQL 9.0 as Windows Service
Just run 'Command Prompt' as windows administrator and run the below command:
pg_ctl.exe register -N PostgreSQL -D "D:/Program Files/PostgreSQL/9.0.4/db_data"
You don't need to specify a User and Password, as previous answers have suggested.
Use the register
parameter for the pg_ctl
program.
The data directory should not be stored in Program Files
, the location of %ProgramData%
is e.g. a good choice.
pg_ctl.exe register -N PostgreSQL -U some_windows_username -P windows_password -D "%ProgramData%/db_data" ...
In newer versions of Postgres, a separate Windows account is no longer necessary, so the following is also sufficient
pg_ctl.exe register -N PostgreSQL -D "%ProgramData%/db_data" ...
Details are in the manual: http://www.postgresql.org/docs/current/static/app-pg-ctl.html
You need to make sure the directory D:/Program Files/PostgreSQL/9.0.4/db_data
has the correct privileges for the windows user you specify with the -U
flag.
Btw: it is a bad idea to store program data in Program Files
. You should move the data directory somewhere outside of Program Files
because Program Files
is usually highly restricted for regular users - with a very good reason.