Re: Add pg_accept_connections_start_time() for better uptime calculation

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

Re: Add pg_accept_connections_start_time() for better uptime calculation

От:
Laurenz Albe <laurenz.albe@cybertec.at>
Дата:
On Sun, 2025-02-16 at 17:35 +1030, Robins Tharakan wrote:
> This patch introduces a new function pg_accept_connections_start_time().
> 
> Currently, pg_postmaster_start_time() is used to determine when the
> database started. However, this is not accurate since the postmaster
> process can sometimes be up whereas the database is not accepting
> connections (for e.g. during child process crash [1], 
> long crash-recovery etc.)
> 
> This can lead to inaccurate database uptime calculations.
> 
> The new function, pg_accept_connections_start_time(), returns the
> time when the database became ready to accept connections. This is
> helpful, since in both of the above cases (quick crash-recovery on
> child process crash, long crash-recovery on startup), this timestamp
> would get reset - an example scenario given below [3].
> 
> This function can be used to tell:
> 1. Whether the database did a quick crash-recovery (without
>    a postmaster restart) in a production setup. In particular, this would
>    help a long-running client confirm whether a connection blip was a
>    server restart, or a session-abort / network / client-side issue [2].
> 2. Calculate database uptime (more accurately)
> 
> The patch passes `make check`, adds a brief function description
> in func.sgml, works in single-user mode and applies cleanly on
> master as of 9e17ac997 (14th Feb).
> 
> Look forward to feedback, but in particular:
> - Good to have a second opinion on a better position to capture
> timestamp during startup in single-user mode.
> - Function name - I think it is too verbose, but it felt most unambiguous.

I myself have never felt the need for such a function - but perhaps it
can be useful in these times of hosted database services, when accessing
the log file might be difficult.

I would probably have called the function pg_uptime(), yet maybe that
is too Unix-centric.

Would it make sense to add that information to the output of
"pg_ctl status" as well?  Perhaps as a new option, so that default output
format doesn't change.

Yours,
Laurenz Albe

-- 

*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den 
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat 
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, 
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder 
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich 
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.

*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are 
confidential and may be privileged or otherwise protected from disclosure 
and solely for the use of the person(s) or entity to whom it is intended. 
If you have received this message in error and are not the intended 
recipient, please notify the sender immediately and delete this message and 
any attachment from your system. If you are not the intended recipient, be 
advised that any use of this message is prohibited and may be unlawful, and 
you must not copy this message or attachment or disclose the contents to 
any other person.


Re: Add pg_accept_connections_start_time() for better uptime calculation

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Michael Paquier  writes:
> On Sun, Feb 16, 2025 at 11:47:46AM +0100, Laurenz Albe wrote:
>> Would it make sense to add that information to the output of
>> "pg_ctl status" as well?  Perhaps as a new option, so that default output
>> format doesn't change.

> A separate function that only returns the open-for-connection time has
> benefits on its own because its execution can be granted to separate
> users, without knowing about the full contents of postmaster.pid.
> That last part should matter for cloud vendors.  And this file only
> knows about MyStartTime.

Yeah.  Making that happen would require extending the contents of
postmaster.pid, which is likely to break assorted peoples' tooling.
I doubt that this feature clears the bar for justifying that.

			regards, tom lane


FAQ