Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register and run PostgreSQL 9.0 as Windows Service

Tags:

postgresql

For a while i have my db running on a command window because im not figuring out how to run it as a windows service.

Since i have the zip file version downloaded. how can i register the pg_ctl command as a windows service?

By the way, im using the following line to start the server:

"D:/Program Files/PostgreSQL/9.0.4/bin/pg_ctl.exe" -D "D:/Program Files/PostgreSQL/9.0.4/db_data" -l logfile start

Thanks in advance.

like image 900
thclpr Avatar asked Jan 23 '13 16:01

thclpr


People also ask

Can PostgreSQL run on Windows server?

This installer can run in graphical or silent install modes. The installer is designed to be a straightforward, fast way to get up and running with PostgreSQL on Windows. Advanced users can also download a zip archive of the binaries, without the installer.


2 Answers

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.

like image 142
a_horse_with_no_name Avatar answered Nov 16 '22 00:11

a_horse_with_no_name


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.

like image 31
Geek669 Avatar answered Nov 16 '22 01:11

Geek669