Re: Can we have a new SQL callable function to get Postmaster PID? - Mailing list pgsql-hackers

From Tomas Vondra
Subject Re: Can we have a new SQL callable function to get Postmaster PID?
Date
Msg-id bd778517-aaef-6576-3551-7dacccb237e0@enterprisedb.com
Whole thread Raw
In response to Can we have a new SQL callable function to get Postmaster PID?  (Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>)
Responses Re: Can we have a new SQL callable function to get Postmaster PID?
List pgsql-hackers
On 2/3/21 7:12 AM, Bharath Rupireddy wrote:
> Hi,
> 
> Can we have a new function, say pg_postgres_pid(), to return
> postmaster PID similar to pg_backend_pid()? At times, it will be
> difficult to use OS level commands to get the postmaster pid of a
> backend to which it is connected. It's even worse if we have multiple
> postgres server instances running on the same system. I'm not sure
> whether it's safe to expose postmaster pid this way, but it will be
> useful at least for debugging purposes on say Windows or other
> non-Linux platforms where it's a bit difficult to get process id.
> Users can also look at the postmaster.pid file to figure out what's
> the current postmaster pid, if not using OS level commands, but having
> a SQL callable function makes life easier.
> 
> The function can look like this:
> Datum
> pg_postgres_pid(PG_FUNCTION_ARGS)
> {
>     PG_RETURN_INT32(PostmasterPid);
> }
> 
> Thoughts?
> 

Curious question - why do you actually need PID of the postmaster? For
debugging, I'd say it's not quite necessary - you can just attach a
debugger to the backend and print the PostmasterPid directly. Or am I
missing something?


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: David Steele
Date:
Subject: Re: Next Commitfest Manager.
Next
From: Tomas Vondra
Date:
Subject: Re: Can we have a new SQL callable function to get Postmaster PID?