Re: Starting PostgreSQL as an NT Service

Lists: pgsql-hackers-win32
From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: "John Meinel" <john(at)johnmeinel(dot)com>
Cc: <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: Starting PostgreSQL as an NT Service
Date: 2004-06-30 18:39:39
Message-ID: 6EE64EF3AB31D5448D0007DD34EEB34101AEA1@Herge.rcsinc.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers-win32


> I just downloaded the latest binary (as of today). I can get it to
> register with pg_ctl register. I had to create an account for it to
run
> as, since you don't allow a user with admin rights.
>
> If I just do
> pg_ctl register -U postgres
> C:\postgres>net start postgresql
> System error 1069 has occurred.
>
> The service did not start due to a logon failure.
>
> I get this if the password for postgres is empty.
> So I added a password for user postgres ('a'), and tried again:
>
> C:\postgres>pg_ctl unregister -N PostgreSQL
>
> C:\postgres>pg_ctl register -U LILIANA\postgres -P a
>
> C:\postgres>net start postgresql
> The service is not responding to the control function.
>
> More help is available by typing NET HELPMSG 2186.
>
> I can start the service manually using:
>
> C:\postgres>runas /env /user:postgres "pg_ctl start -l logfile"
> Enter the password for postgres:
> Attempting to start pg_ctl start -l logfile as user
"LILIANA\postgres"..
>
> However, this leaves a dos-box running with "postmaster starting". I'm
> pretty sure this is because postmaster is running as a child of cmd.
> Because I can't stop this box, but if I run:
>
> C:\postgres>runas /env /user:postgres "pg_ctl stop"
> Enter the password for postgres:
> Attempting to start pg_ctl stop as user "LILIANA\postgres" ...

There are couple of gotchas:
1. The account that is starting postgresql can not have administrator
privileges. This is a safety issue...works the same on unix.

2. The account starting postgresql must have 'log on as a service'
privilege. More about this in a sec.

3. Make sure the postgresql NT user (in your case: 'postgres') has
permissions to the data folder. Add this user to the folder and make
sure you apply the permissions to the subfolders. It goes without
saying that the data folder should *not* be shared to the outside world
in any way.

4. Make sure you ran initdb previous to attempting to resister server.

You can omit the -U parameter to pg_ctl and play around with the
accounts with the service directly (select log on as... in service
properties). It's easier there because you get more detailed error
information and you don't have to keep re-registering the server.

Merlin


From: "Darko Prenosil" <Darko(dot)Prenosil(at)finteh(dot)hr>
To: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>, "John Meinel" <john(at)johnmeinel(dot)com>
Cc: <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: Starting PostgreSQL as an NT Service
Date: 2004-06-30 21:00:55
Message-ID: 004301c45ee5$813e4500$3289bfd5@darko
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers-win32

I registerd the service using the bat file:

d:
cd pgsql\bin
"pg_ctl.exe" unregister -N postgres
"d:\pgsql\bin\pg_ctl.exe" register -N postgres -U postgres -P
elephant5432 -D d:\pgsql\data"
net start postgres

I got :
The description for Event ID ( 0 ) in Source ( PostgreSQL ) cannot be found.
The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. The following
information is part of the event: Unable to find exe.

message written to event viewer.

d:\pgsql\bin is in the path.

Path to executable in the service manager is:

d:/pgsql/bin/pg_ctl.exe runservice -N "postgres" -D "d:/pgsql/data"

initdb finished OK, postgres is opened as unpriviledged user etc...

Why pg_ctl can't find postmaster ? Any sugestions ?

Regards !

----- Original Message -----
From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: "John Meinel" <john(at)johnmeinel(dot)com>
Cc: <pgsql-hackers-win32(at)postgresql(dot)org>
Sent: Wednesday, June 30, 2004 8:39 PM
Subject: Re: [pgsql-hackers-win32] Starting PostgreSQL as an NT Service

> I just downloaded the latest binary (as of today). I can get it to
> register with pg_ctl register. I had to create an account for it to
run
> as, since you don't allow a user with admin rights.
>
> If I just do
> pg_ctl register -U postgres
> C:\postgres>net start postgresql
> System error 1069 has occurred.
>
> The service did not start due to a logon failure.
>
> I get this if the password for postgres is empty.
> So I added a password for user postgres ('a'), and tried again:
>
> C:\postgres>pg_ctl unregister -N PostgreSQL
>
> C:\postgres>pg_ctl register -U LILIANA\postgres -P a
>
> C:\postgres>net start postgresql
> The service is not responding to the control function.
>
> More help is available by typing NET HELPMSG 2186.
>
> I can start the service manually using:
>
> C:\postgres>runas /env /user:postgres "pg_ctl start -l logfile"
> Enter the password for postgres:
> Attempting to start pg_ctl start -l logfile as user
"LILIANA\postgres"..
>
> However, this leaves a dos-box running with "postmaster starting". I'm
> pretty sure this is because postmaster is running as a child of cmd.
> Because I can't stop this box, but if I run:
>
> C:\postgres>runas /env /user:postgres "pg_ctl stop"
> Enter the password for postgres:
> Attempting to start pg_ctl stop as user "LILIANA\postgres" ...

There are couple of gotchas:
1. The account that is starting postgresql can not have administrator
privileges. This is a safety issue...works the same on unix.

2. The account starting postgresql must have 'log on as a service'
privilege. More about this in a sec.

3. Make sure the postgresql NT user (in your case: 'postgres') has
permissions to the data folder. Add this user to the folder and make
sure you apply the permissions to the subfolders. It goes without
saying that the data folder should *not* be shared to the outside world
in any way.

4. Make sure you ran initdb previous to attempting to resister server.

You can omit the -U parameter to pg_ctl and play around with the
accounts with the service directly (select log on as... in service
properties). It's easier there because you get more detailed error
information and you don't have to keep re-registering the server.

Merlin

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


From: John Meinel <john(at)johnmeinel(dot)com>
To: Merlin Moncure <merlin(dot)moncure(at)rcsonline(dot)com>, pgsql-hackers-win32(at)postgresql(dot)org
Subject: Re: Starting PostgreSQL as an NT Service
Date: 2004-07-01 02:10:46
Message-ID: 40E372A6.4020007@johnmeinel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers-win32

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Merlin Moncure wrote:

|
|
| There are couple of gotchas:
| 1. The account that is starting postgresql can not have administrator
| privileges. This is a safety issue...works the same on unix.

I have done that.

|
| 2. The account starting postgresql must have 'log on as a service'
| privilege. More about this in a sec.

Is there a way you can create this explicitly? I remember when I went to
Computer Management/Services, and chose the username of "postgres" it
told me that it gave the user "Log on as a service" rights.
|
| 3. Make sure the postgresql NT user (in your case: 'postgres') has
| permissions to the data folder. Add this user to the folder and make
| sure you apply the permissions to the subfolders. It goes without
| saying that the data folder should *not* be shared to the outside world
| in any way.
|
| 4. Make sure you ran initdb previous to attempting to resister server.
|
| You can omit the -U parameter to pg_ctl and play around with the
| accounts with the service directly (select log on as... in service
| properties). It's easier there because you get more detailed error
| information and you don't have to keep re-registering the server.
|
| Merlin

Actually, I found out what was wrong. I had put 'c:\postgres\bin' and
'c:\postgres\lib' into my user path, but that meant it _wasn't_ in the
user postgres's path. After logging in as postgres, I modified the PATH
environment variable. And then it started up. I think the main issue is
it is looking for libpq.dll which exists in lib, because it can probably
find the rest of the programs that exist in bin.

I have to say, the error messages aren't very helpful. But I'm glad I
asked the question, because now someone might be able to find the
solution by searching.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Cygwin)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFA43KmJdeBCYSNAAMRAl5uAJ9ra/nQ4nAq0QiWmhkqSojPsWIgMwCfRHZL
FywOQ9QT/fBBpYAIA1qzVlE=
=elu0
-----END PGP SIGNATURE-----