Thread: Start service

Start service

From
Brad White
Date:
I'm trying to start a v15 service on a Windows 2012 R2 server where it hasn't been used for a while.
The service is set to run as pgUser.
pgUser owns the Postgres directory, including the data dir.

The command the service is using is
    ' "C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" runservice -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w'

First off, it's interesting that "runservice" isn't listed as an option for pg_ctl.

Windows Event Viewer shows it starting up, handing off logging to pg_log, then timing out.
     Waiting for server startup...
     2023-09-22 12:31:15.173 CDT [5000] LOG:  redirecting log output to logging collector process
     2023-09-22 12:31:15.173 CDT [5000] HINT:  Future log output will appear in directory "pg_log".
     Timed out waiting for server startup

It does create a log file in pg_log, but it is empty.

If I sub 'start' for 'runservice' and try to start it from CLI, I get
     C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" start
 -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w 
     waiting for server to start....2023-09-22 12:48:05.438 CDT [4796] FATAL:  could
not create lock file "postmaster.pid": Permission denied
     stopped waiting
     pg_ctl: could not start server
     Examine the log output.

And again, I get an empty log file in pg_log.
Is there somewhere else I should check?

I get the same results if I pass username and password with -U and -P

I'm running as administrator, so not sure how I get permission denied
Checking EffectiveAccess shows that admin and pgUser have full control, so I assume this message is a red herring, standing in for the real issue.

Without an actual error message to fix, I'm not sure how to proceed.

Thanks,
Brad.

Re: Start service

From
Nick Ivanov
Date:
I'd check if there is already "postmaster.pid" in C:\Program Files\PostgreSQL\15\data, left over from a previous abend.

On Fri, Sep 22, 2023 at 2:40 PM Brad White <b55white@gmail.com> wrote:
I'm trying to start a v15 service on a Windows 2012 R2 server where it hasn't been used for a while.
The service is set to run as pgUser.
...
If I sub 'start' for 'runservice' and try to start it from CLI, I get
     C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" start
 -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w 
     waiting for server to start....2023-09-22 12:48:05.438 CDT [4796] FATAL:  could
not create lock file "postmaster.pid": Permission denied

--
Nick Ivanov 
Solution Architect   

Re: Start service

From
Brad White
Date:
Good guess, but no. I should have mentioned that I checked that.

There is, though, a postmaster.opts file that wasn't there earlier. It contains
      C:/Program Files/PostgreSQL/15/bin/postgres.exe  "-D"  "C:\Program Files\PostgreSQL\15\data"
Note the lack of quotes around the exe path.

On Fri, Sep 22, 2023 at 1:48 PM Nick Ivanov <nick.ivanov@enterprisedb.com> wrote:
I'd check if there is already "postmaster.pid" in C:\Program Files\PostgreSQL\15\data, left over from a previous abend.

On Fri, Sep 22, 2023 at 2:40 PM Brad White <b55white@gmail.com> wrote:
I'm trying to start a v15 service on a Windows 2012 R2 server where it hasn't been used for a while.
The service is set to run as pgUser.
...
If I sub 'start' for 'runservice' and try to start it from CLI, I get
     C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" start
 -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w 
     waiting for server to start....2023-09-22 12:48:05.438 CDT [4796] FATAL:  could
not create lock file "postmaster.pid": Permission denied

--
Nick Ivanov 
Solution Architect   

Re: Start service

From
Brad White
Date:
I created the pid file by hand and I get
      C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" start
 -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w -U TMA\pgUse
r -P ***********
       pg_ctl: another server might be running; trying to start server anyway
       waiting for server to start..............2023-09-22 14:31:17.752 CDT [4276] FATA
L:  could not remove old lock file "postmaster.pid": Permission denied
       2023-09-22 14:31:17.752 CDT [4276] HINT:  The file seems accidentally left over,
 but it could not be removed. Please remove the file by hand and try again.
      stopped waiting
      pg_ctl: could not start server
      Examine the log output.

Remove the file and we are back where we started.
But a) we are looking at the right dir, and b) it looks like it might really be a permissions issue somehow.

On Fri, Sep 22, 2023 at 1:56 PM Brad White <b55white@gmail.com> wrote:
Good guess, but no. I should have mentioned that I checked that.

There is, though, a postmaster.opts file that wasn't there earlier. It contains
      C:/Program Files/PostgreSQL/15/bin/postgres.exe  "-D"  "C:\Program Files\PostgreSQL\15\data"
Note the lack of quotes around the exe path.

On Fri, Sep 22, 2023 at 1:48 PM Nick Ivanov <nick.ivanov@enterprisedb.com> wrote:
I'd check if there is already "postmaster.pid" in C:\Program Files\PostgreSQL\15\data, left over from a previous abend.

On Fri, Sep 22, 2023 at 2:40 PM Brad White <b55white@gmail.com> wrote:
I'm trying to start a v15 service on a Windows 2012 R2 server where it hasn't been used for a while.
The service is set to run as pgUser.
...
If I sub 'start' for 'runservice' and try to start it from CLI, I get
     C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" start
 -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w 
     waiting for server to start....2023-09-22 12:48:05.438 CDT [4796] FATAL:  could
not create lock file "postmaster.pid": Permission denied

--
Nick Ivanov 
Solution Architect   

Re: Start service

From
postgresql439848@heinz-it.de
Date:
Am 22.09.23 um 20:40 schrieb Brad White:
> I'm trying to start a v15 service on a Windows 2012 R2 server where it
> hasn't been used for a while.
> The service is set to run as pgUser.
> pgUser owns the Postgres directory, including the data dir.
>
> The command the service is using is
>      ' "C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" runservice -N
> "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w'
>
> First off, it's interesting that "runservice" isn't listed as an option for
> pg_ctl.
>
> Windows Event Viewer shows it starting up, handing off logging to pg_log,
> then timing out.
>       Waiting for server startup...
>       2023-09-22 12:31:15.173 CDT [5000] LOG:  redirecting log output to
> logging collector process
>       2023-09-22 12:31:15.173 CDT [5000] HINT:  Future log output will
> appear in directory "pg_log".
>       Timed out waiting for server startup
>
> It does create a log file in pg_log, but it is empty.
>
> If I sub 'start' for 'runservice' and try to start it from CLI, I get
>       C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe"
> start
>   -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w
>       waiting for server to start....2023-09-22 12:48:05.438 CDT [4796]
> FATAL:  could
> not create lock file "postmaster.pid": Permission denied
>       stopped waiting
>       pg_ctl: could not start server
>       Examine the log output.
>
> And again, I get an empty log file in pg_log.
> Is there somewhere else I should check?
>
> I get the same results if I pass username and password with -U and -P
>
> I'm running as administrator, so not sure how I get permission denied
> Checking EffectiveAccess shows that admin and pgUser have full control, so
> I assume this message is a red herring, standing in for the real issue.
>
> Without an actual error message to fix, I'm not sure how to proceed.
>
> Thanks,
> Brad.
>
if you want to run postgresql server then you could use "pg_ctl start ..."
but to run it as a windows service you first need to register it as a 
service. so look at pg_ctl register in the options.



Re: Start service

From
Brad White
Date:
So, there were two issues.
Even though admin is in the admin group and had Full Control under effective permissions, somehow that wasn't enough.
I noticed that I can run the v14 service, but it had Admin explicitly listed with full control on Data.
Once I added that, I started getting error messages when run from CLI and could fix the issue in pg_hba.conf.
Now the service starts.

Thanks,
Brad.

On Fri, Sep 22, 2023 at 2:43 PM <postgresql439848@heinz-it.de> wrote:
Am 22.09.23 um 20:40 schrieb Brad White:
> I'm trying to start a v15 service on a Windows 2012 R2 server where it
> hasn't been used for a while.
> The service is set to run as pgUser.
> pgUser owns the Postgres directory, including the data dir.
>
> The command the service is using is
>      ' "C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe" runservice -N
> "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w'
>
> First off, it's interesting that "runservice" isn't listed as an option for
> pg_ctl.
>
> Windows Event Viewer shows it starting up, handing off logging to pg_log,
> then timing out.
>       Waiting for server startup...
>       2023-09-22 12:31:15.173 CDT [5000] LOG:  redirecting log output to
> logging collector process
>       2023-09-22 12:31:15.173 CDT [5000] HINT:  Future log output will
> appear in directory "pg_log".
>       Timed out waiting for server startup
>
> It does create a log file in pg_log, but it is empty.
>
> If I sub 'start' for 'runservice' and try to start it from CLI, I get
>       C:\Users\administrator>"C:\Program Files\PostgreSQL\15\bin\pg_ctl.exe"
> start
>   -N "postgresql-x64-15" -D "C:\Program Files\PostgreSQL\15\data" -w
>       waiting for server to start....2023-09-22 12:48:05.438 CDT [4796]
> FATAL:  could
> not create lock file "postmaster.pid": Permission denied
>       stopped waiting
>       pg_ctl: could not start server
>       Examine the log output.
>
> And again, I get an empty log file in pg_log.
> Is there somewhere else I should check?
>
> I get the same results if I pass username and password with -U and -P
>
> I'm running as administrator, so not sure how I get permission denied
> Checking EffectiveAccess shows that admin and pgUser have full control, so
> I assume this message is a red herring, standing in for the real issue.
>
> Without an actual error message to fix, I'm not sure how to proceed.
>
> Thanks,
> Brad.
>
if you want to run postgresql server then you could use "pg_ctl start ..."
but to run it as a windows service you first need to register it as a
service. so look at pg_ctl register in the options.