Re: Postgres: Installing as a service

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Postgres: Installing as a service
Date: 2009-04-13 07:01:54
Message-ID: 49E2E362.2070704@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Craig Ringer wrote:
> CM J wrote:
>
>> Hi ,
>>
>> I have extracted postgres from postgres-noinstaller.zip file. How do
>> i install postgres as a service from cmd line ?
>>
>
> Search: http://msdn.microsoft.com/
>
> You can use the `net' command to start/stop services. I don't recall the
> command(s) used to install them, if any, but you'll be able to find the
> info on MSDN.
>

sc is the command line tool for installing/configuring services. you'll
need to create a service account with NET USER, then configure the pgsql
service to run as that user.

the standard postgresql windows installer configures it to look like...

C:\>sc queryex pgsql-8.3

SERVICE_NAME: pgsql-8.3
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
PID : 1256
FLAGS :

C:\>sc qc pgsql-8.3
[SC] GetServiceConfig SUCCESS

SERVICE_NAME: pgsql-8.3
TYPE : 10 WIN32_OWN_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : D:\postgres\8.3\bin\pg_ctl.exe runservice
-w -N "pgsql-8.3" -D "D:\postgres\8.3\data\"
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : PostgreSQL Database Server 8.3
DEPENDENCIES :
SERVICE_START_NAME : .\postgres

so the commands to create tthis would be something like...

C:\>net user postgres 3gesIjita%9 /add
C:\>sc create pgsql-8.3 binpath= "D:\postgres\8.3\bin\pg_ctl.exe
runservice -w -N pgsql-8.3 -D D:\postgres\8.3\data\" type= own start=
auto displayname= "PostgreSQL Database Server 8.3" obj= .\postgres
password= 3gesIjita%9
C:\>sc start pgsql-8.3

and pray. note I intentionally installed postgresql to a directory
with no spaces in its name to dodge issues with nested quotes.
3gesIjita%9 is just a random password I concocted.

note, those sc commands have a funny syntax, the = MUST have no space
before it and MUST have a space after it.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2009-04-13 07:20:21 Re: Postgres: Installing as a service
Previous Message Craig Ringer 2009-04-13 06:45:04 Re: Postgres: Installing as a service