Re: pg_ctl behavior on Windows - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: pg_ctl behavior on Windows
Date
Msg-id CAA4eK1KytynF3xd26X9ReNio14qSqbUkxb0xgKZZuFGnT3Vu+A@mail.gmail.com
Whole thread Raw
In response to pg_ctl behavior on Windows  (Chapman Flack <chap@anastigmatix.net>)
Responses Re: pg_ctl behavior on Windows
Re: pg_ctl behavior on Windows
List pgsql-hackers
On Sat, Jul 18, 2020 at 5:33 AM Chapman Flack <chap@anastigmatix.net> wrote:
>
> But there's a NOTE! in the comment for CreateRestrictedProcess: "Job object
> will only work when running as a service, because it's automatically
> destroyed when pg_ctl exits."
>
> I haven't been able to find any documentation of what that really means
> in practical terms, or quite figure it out from the code. Does that mean
> 'pg_ctl start' won't really work after all from a privileged account, or
> will seem to work but something will go wrong after the server is ready
> and pg_ctl exits? Does it mean the tersely-documented 'register' operation
> must be used, and that's the only way to start from a privileged account?
>

I don't think so.  I think you can use 'pg_ctl start' to achieve that.
I think the JOBS stuff is primarily required when we use 'register'
operation (aka runs server via service). For example, if you see one
of the Job options "JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION", it
suppresses dialog box for a certain type of errors and causes a
termination of the process with the exception code as the exit status
(See [1]) which I think is essential for a service.

> I don't have an especially easy way to experiment on Windows; I can push
> experiments to the CI service and wait a bit to see what they do, but
> I figured I'd ask here first.
>

I have tried and 'pg_ctl stuff seems to be working for a privileged
account.  See below:
postgres.exe -D ..\..\Data
Execution of PostgreSQL by a user with administrative permissions is
not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromises.  See the documentation for
more information on how to properly start the server.

pg_ctl.exe start -D ..\..\Data
waiting for server to start....2020-07-18 14:53:46.120 IST [8468] LOG:
 starting PostgreSQL 14devel, compiled by Visual C++ build 1915,
64-bit
2020-07-18 14:53:46.136 IST [8468] LOG:  listening on IPv6 address
"::1", port 5432
2020-07-18 14:53:46.136 IST [8468] LOG:  listening on IPv4 address
"127.0.0.1", port 5432
2020-07-18 14:53:46.214 IST [7512] LOG:  database system was shut down
at 2020-07-18 14:53:22 IST
2020-07-18 14:53:46.245 IST [8468] LOG:  database system is ready to
accept connections
 done
server started

I have run above two commands from an account with administrative
privilege and 'pg_ctl start' is working.  I have further tried a few
operations after connecting with the client and everything is working
fine.

[1] - https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_limit_information

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Patch for reorderbuffer.c documentation.
Next
From: vignesh C
Date:
Subject: Re: Added tab completion for the missing options in copy statement