mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Refactor ps_status.c API
The init_ps_display() arguments were mostly lies by now, so to match
typical usage, just use one argument and let the caller assemble it
from multiple sources if necessary. The only user of the additional
arguments is BackendInitialize(), which was already doing string
assembly on the caller side anyway.
Remove the second argument of set_ps_display() ("force") and just
handle that in init_ps_display() internally.
BackendInitialize() also used to set the initial status as
"authentication", but that was very far from where authentication
actually happened. So now it's set to "initializing" and then
"authentication" just before the actual call to
ClientAuthentication().
Reviewed-by: Julien Rouhaud <rjuju123@gmail.com>
Reviewed-by: Kuntal Ghosh <kuntalghosh.2007@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@2ndquadrant.com>
Discussion: https://www.postgresql.org/message-id/flat/c65e5196-4f04-4ead-9353-6088c19615a3@2ndquadrant.com
This commit is contained in:
@@ -4282,7 +4282,7 @@ BackendInitialize(Port *port)
|
||||
int ret;
|
||||
char remote_host[NI_MAXHOST];
|
||||
char remote_port[NI_MAXSERV];
|
||||
char remote_ps_data[NI_MAXHOST];
|
||||
StringInfoData ps_data;
|
||||
|
||||
/* Save port etc. for ps status */
|
||||
MyProcPort = port;
|
||||
@@ -4346,10 +4346,6 @@ BackendInitialize(Port *port)
|
||||
ereport(WARNING,
|
||||
(errmsg_internal("pg_getnameinfo_all() failed: %s",
|
||||
gai_strerror(ret))));
|
||||
if (remote_port[0] == '\0')
|
||||
snprintf(remote_ps_data, sizeof(remote_ps_data), "%s", remote_host);
|
||||
else
|
||||
snprintf(remote_ps_data, sizeof(remote_ps_data), "%s(%s)", remote_host, remote_port);
|
||||
|
||||
/*
|
||||
* Save remote_host and remote_port in port structure (after this, they
|
||||
@@ -4423,21 +4419,21 @@ BackendInitialize(Port *port)
|
||||
/*
|
||||
* Now that we have the user and database name, we can set the process
|
||||
* title for ps. It's good to do this as early as possible in startup.
|
||||
*
|
||||
* For a walsender, the ps display is set in the following form:
|
||||
*
|
||||
* postgres: walsender <user> <host> <activity>
|
||||
*
|
||||
* To achieve that, we pass "walsender" as username and username as dbname
|
||||
* to init_ps_display(). XXX: should add a new variant of
|
||||
* init_ps_display() to avoid abusing the parameters like this.
|
||||
*/
|
||||
initStringInfo(&ps_data);
|
||||
if (am_walsender)
|
||||
init_ps_display(pgstat_get_backend_desc(B_WAL_SENDER), port->user_name, remote_ps_data,
|
||||
update_process_title ? "authentication" : "");
|
||||
else
|
||||
init_ps_display(port->user_name, port->database_name, remote_ps_data,
|
||||
update_process_title ? "authentication" : "");
|
||||
appendStringInfo(&ps_data, "%s ", pgstat_get_backend_desc(B_WAL_SENDER));
|
||||
appendStringInfo(&ps_data, "%s ", port->user_name);
|
||||
if (!am_walsender)
|
||||
appendStringInfo(&ps_data, "%s ", port->database_name);
|
||||
appendStringInfo(&ps_data, "%s", port->remote_host);
|
||||
if (port->remote_port[0] != '\0')
|
||||
appendStringInfo(&ps_data, "(%s)", port->remote_port);
|
||||
|
||||
init_ps_display(ps_data.data);
|
||||
pfree(ps_data.data);
|
||||
|
||||
set_ps_display("initializing");
|
||||
|
||||
/*
|
||||
* Disable the timeout, and prevent SIGTERM/SIGQUIT again.
|
||||
|
||||
Reference in New Issue
Block a user