Обсуждение: Starting PostgreSQL as an NT Service

Поиск
Список
Период
Сортировка

Starting PostgreSQL as an NT Service

От
"Hans Oesterholt Dijkema"
Дата:
L.S.,

I've made a simple wrapper to be able to start
the new native win32 port of PostgreSQL as an
NT Service.

One can download the sources from

    http://elementals.sf.net

Best regards,
--
Hans Oesterholt-Dijkema


Re: Starting PostgreSQL as an NT Service

От
"Dave Page"
Дата:

> -----Original Message-----
> From: pgsql-hackers-win32-owner@postgresql.org
> [mailto:pgsql-hackers-win32-owner@postgresql.org] On Behalf
> Of Hans Oesterholt Dijkema
> Sent: 24 June 2004 14:42
> To: pgsql-hackers-win32@postgresql.org
> Subject: [pgsql-hackers-win32] Starting PostgreSQL as an NT Service
>
> L.S.,
>
> I've made a simple wrapper to be able to start the new native
> win32 port of PostgreSQL as an NT Service.
>

There is a patch in the queue for this already :-(

http://archives.postgresql.org/pgsql-patches/2004-06/msg00310.php

Regards, Dave.

Re: Starting PostgreSQL as an NT Service

От
"Merlin Moncure"
Дата:
> L.S.,
>
> I've made a simple wrapper to be able to start
> the new native win32 port of PostgreSQL as an
> NT Service.
>
> One can download the sources from
>
>     http://elementals.sf.net
>
> Best regards,
> --
> Hans Oesterholt-Dijkema
>

The real challenge with running pg as a service is not the Service
Handler itself, but modification of the postmaster so that pg plays
friendly with the event manager the current (as-of-yet-unapplied) patch
routs all the logging except startup/shutdown to dev/null.

Merlin

Re: Starting PostgreSQL as an NT Service

От
Andrew Dunstan
Дата:
Merlin Moncure wrote:

>>L.S.,
>>
>>I've made a simple wrapper to be able to start
>>the new native win32 port of PostgreSQL as an
>>NT Service.
>>
>>One can download the sources from
>>
>>    http://elementals.sf.net
>>
>>Best regards,
>>--
>>Hans Oesterholt-Dijkema
>>
>>
>>
>
>The real challenge with running pg as a service is not the Service
>Handler itself, but modification of the postmaster so that pg plays
>friendly with the event manager the current (as-of-yet-unapplied) patch
>routs all the logging except startup/shutdown to dev/null.
>
>
>

I thought we were going to do all this via pg_ctl ...

cheers

andrew

Re: Starting PostgreSQL as an NT Service

От
"Merlin Moncure"
Дата:
> >The real challenge with running pg as a service is not the Service
> >Handler itself, but modification of the postmaster so that pg plays
> >friendly with the event manager the current (as-of-yet-unapplied)
patch
> >routs all the logging except startup/shutdown to dev/null.
> >
> I thought we were going to do all this via pg_ctl ...

Yes...(Magnus could tell you more about this), but as I understand it,
some changes to postmaster.c were required.

Merlin

Re: Starting PostgreSQL as an NT Service

От
"Sarah Tanembaum"
Дата:
"Andrew Dunstan" <andrew@dunslane.net> wrote in message
news:40DB2030.7080500@dunslane.net...
> Merlin Moncure wrote:
>
> >>L.S.,
> >>
> >>I've made a simple wrapper to be able to start
> >>the new native win32 port of PostgreSQL as an
> >>NT Service.
> >>
> >>One can download the sources from
> >>
> >>    http://elementals.sf.net
> >>
> >>Best regards,
> >>--
> >>Hans Oesterholt-Dijkema
> >>
> >>
> >>
> >
> >The real challenge with running pg as a service is not the Service
> >Handler itself, but modification of the postmaster so that pg plays
> >friendly with the event manager the current (as-of-yet-unapplied) patch
> >routs all the logging except startup/shutdown to dev/null.
> >
> >
> >
>
> I thought we were going to do all this via pg_ctl ...
>
> cheers
>
> andrew
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>

May be you guys can tell me where can I get the native Win32 binaries port
of the latest PostgreSQL. I got the latest one compiled under Cygwin.
Thanks



Re: Starting PostgreSQL as an NT Service

От
"Merlin Moncure"
Дата:
> "Andrew Dunstan" <andrew@dunslane.net> wrote in message
> news:40DB2030.7080500@dunslane.net...
> > Merlin Moncure wrote:
> May be you guys can tell me where can I get the native Win32 binaries
port
> of the latest PostgreSQL. I got the latest one compiled under Cygwin.
> Thanks

The latest binary available here:
http://www.hagander.net/pgsql/win32snap/

has the new pg_ctl with the SCM.  Follow the instructions on the page to
do the install.  Since you have cygwin postgres, make sure you do not
have any library/path conflicts with cygwin version.  (If you are only
running cygwin for postgres, you might want to consider dropping cygwin
environment in favor of mingw, don't be hasty tho!).

This version has native ability to install as a service.  Quick guide:

pg_ctl register -U account_to_login_as [-P password]
net start postgresql
net stop postgresql etc.

If you want detail logging you probably shouldn't be using the SCM yet.
Manually starting with pg_ctl still (as of this writing) offers the most
flexibility.

p.s. the binary version is again ssl enabled as it says in the
instructions.

Merlin

Re: Starting PostgreSQL as an NT Service

От
"Merlin Moncure"
Дата:
> 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


Re: Starting PostgreSQL as an NT Service

От
"Darko Prenosil"
Дата:
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.moncure@rcsonline.com>
To: "John Meinel" <john@johnmeinel.com>
Cc: <pgsql-hackers-win32@postgresql.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



Re: Starting PostgreSQL as an NT Service

От
"Merlin Moncure"
Дата:
Darko Prenosil wrote:
> 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...

1. Is the your path on the system side or the user side (make sure it's
on the system side for services).
2. Try setting up PGDATA (in system env. variables) to avoid use of -D
option.
3. Try logging in as user postgres and invoking postmaster directly from
shell.
4. Double check NTFS permissions to 'local' folder (make sure postgres
has read/execute) and to data folder (make sure postgres has full
control)

Merlin

Re: Starting PostgreSQL as an NT Service

От
"Darko Prenosil"
Дата:
running pg_ctl from postgres account gives :

D:\pgsql\bin>LOG:  could not recognize system timezone, defaulting to
"Etc/GMT-1"
HINT:  You can specify the correct timezone in postgresql.conf.
LOG:  database system was shut down at 2004-06-30 21:42:59 Central European
Daylight Time
LOG:  checkpoint record is at 0/A76CC0
LOG:  redo record is at 0/A76CC0; undo record is at 0/0; shutdown TRUE
LOG:  next transaction ID: 492; next OID: 17227
LOG:  database system is ready

,so it is working...

loged in again, unregistered service, set the PGDATA, registered service as:
    pg_ctl register -N postgres -U postgres -P elephant5432
but the error is still here :-(
I'll try to figure out what is wrong by putting some debug messages inside
"find_other_exec" function.

Regards !

----- Original Message -----
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Darko Prenosil" <Darko.Prenosil@finteh.hr>
Cc: <pgsql-hackers-win32@postgresql.org>
Sent: Wednesday, June 30, 2004 11:08 PM
Subject: Re: [pgsql-hackers-win32] Starting PostgreSQL as an NT Service


Darko Prenosil wrote:
> 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...

1. Is the your path on the system side or the user side (make sure it's
on the system side for services).
2. Try setting up PGDATA (in system env. variables) to avoid use of -D
option.
3. Try logging in as user postgres and invoking postmaster directly from
shell.
4. Double check NTFS permissions to 'local' folder (make sure postgres
has read/execute) and to data folder (make sure postgres has full
control)

Merlin

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)




Re: Starting PostgreSQL as an NT Service

От
"Merlin Moncure"
Дата:
loged in again, unregistered service, set the PGDATA, registered service
> as:
>     pg_ctl register -N postgres -U postgres -P elephant5432
> but the error is still here :-(

hmmmm. Is the postgres service in the services MMC snapin? Try logging
in from there.

Merlin

Re: Starting PostgreSQL as an NT Service

От
"Darko Prenosil"
Дата:
Yes, it is , actually when I said:

>Path to executable in the service manager is:
>    d:/pgsql/bin/pg_ctl.exe runservice -N "postgres" -D "d:/pgsql/data"

, I ment this is what I see after opening service property dialog in MMC.

Regards !


----- Original Message -----
From: "Merlin Moncure" <merlin.moncure@rcsonline.com>
To: "Darko Prenosil" <Darko.Prenosil@finteh.hr>
Cc: <pgsql-hackers-win32@postgresql.org>
Sent: Thursday, July 01, 2004 12:01 AM
Subject: Re: [pgsql-hackers-win32] Starting PostgreSQL as an NT Service


loged in again, unregistered service, set the PGDATA, registered service
> as:
>     pg_ctl register -N postgres -U postgres -P elephant5432
> but the error is still here :-(

hmmmm. Is the postgres service in the services MMC snapin? Try logging
in from there.

Merlin

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org



Re: Starting PostgreSQL as an NT Service

От
John Meinel
Дата:
-----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-----