/* Report recovery progress in PS display */
snprintf(activitymsg, sizeof(activitymsg), "waiting for %s",
xlogfname);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
restoredFromArchive = RestoreArchivedFile(path, xlogfname,
"RECOVERYXLOG",
/* Report recovery progress in PS display */
snprintf(activitymsg, sizeof(activitymsg), "recovering %s",
xlogfname);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
/* Track source of data in assorted state variables */
readSource = source;
statmsg = "??? process";
break;
}
- init_ps_display(statmsg, "", "", "");
+ init_ps_display(statmsg);
}
/* Acquire configuration parameters, unless inherited from postmaster */
if (Trace_notify)
elog(DEBUG1, "ProcessIncomingNotify");
- set_ps_display("notify interrupt", false);
+ set_ps_display("notify interrupt");
/*
* We must run asyncQueueReadAllNotifications inside a transaction, else
*/
pq_flush();
- set_ps_display("idle", false);
+ set_ps_display("idle");
if (Trace_notify)
elog(DEBUG1, "ProcessIncomingNotify: done");
am_autovacuum_launcher = true;
/* Identify myself via ps */
- init_ps_display(pgstat_get_backend_desc(B_AUTOVAC_LAUNCHER), "", "", "");
+ init_ps_display(pgstat_get_backend_desc(B_AUTOVAC_LAUNCHER));
ereport(DEBUG1,
(errmsg("autovacuum launcher started")));
am_autovacuum_worker = true;
/* Identify myself via ps */
- init_ps_display(pgstat_get_backend_desc(B_AUTOVAC_WORKER), "", "", "");
+ init_ps_display(pgstat_get_backend_desc(B_AUTOVAC_WORKER));
SetProcessingMode(InitProcessing);
*/
InitPostgres(NULL, dbid, NULL, InvalidOid, dbname, false);
SetProcessingMode(NormalProcessing);
- set_ps_display(dbname, false);
+ set_ps_display(dbname);
ereport(DEBUG1,
(errmsg("autovacuum: processing database \"%s\"", dbname)));
IsBackgroundWorker = true;
/* Identify myself via ps */
- init_ps_display(worker->bgw_name, "", "", "");
+ init_ps_display(worker->bgw_name);
/*
* If we're not supposed to have shared memory access, then detach from
/*
* Identify myself via ps
*/
- init_ps_display("archiver", "", "", "");
+ init_ps_display("archiver");
pgarch_MainLoop();
/* Report archive activity in PS display */
snprintf(activitymsg, sizeof(activitymsg), "archiving %s", xlog);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
rc = system(xlogarchcmd);
if (rc != 0)
}
snprintf(activitymsg, sizeof(activitymsg), "failed on %s", xlog);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
return false;
}
elog(DEBUG1, "archived write-ahead log file \"%s\"", xlog);
snprintf(activitymsg, sizeof(activitymsg), "last was %s", xlog);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
return true;
}
/*
* Identify myself via ps
*/
- init_ps_display("stats collector", "", "", "");
+ init_ps_display("stats collector");
/*
* Read in existing stats files or initialize the stats to zero.
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;
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
/*
* 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:
- *
- *
- * 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.
am_syslogger = true;
- init_ps_display("logger", "", "", "");
+ init_ps_display("logger");
/*
* If we restarted, our stderr is already redirected into our own input
snprintf(activitymsg, sizeof(activitymsg), "sending backup \"%s\"",
opt.label);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
}
perform_base_backup(&opt);
memcpy(new_status, old_status, len);
sprintf(new_status + len, " waiting for %X/%X",
(uint32) (lsn >> 32), (uint32) lsn);
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
new_status[len] = '\0'; /* truncate off " waiting ..." */
}
if (new_status)
{
/* Reset ps display */
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
pfree(new_status);
}
}
walrcv->receiveStartTLI = 0;
SpinLockRelease(&walrcv->mutex);
- if (update_process_title)
- set_ps_display("idle", false);
+ set_ps_display("idle");
/*
* nudge startup process to notice that we've stopped streaming and are
snprintf(activitymsg, sizeof(activitymsg), "restarting at %X/%X",
(uint32) (*startpoint >> 32),
(uint32) *startpoint);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
}
}
snprintf(activitymsg, sizeof(activitymsg), "streaming %X/%X",
(uint32) (LogstreamResult.Write >> 32),
(uint32) LogstreamResult.Write);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
}
/* Also let the master know that we made some progress */
snprintf(activitymsg, sizeof(activitymsg), "streaming %X/%X",
(uint32) (sentPtr >> 32), (uint32) sentPtr);
- set_ps_display(activitymsg, false);
+ set_ps_display(activitymsg);
}
}
new_status = (char *) palloc(len + 8 + 1);
memcpy(new_status, old_status, len);
strcpy(new_status + len, " waiting");
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
new_status[len] = '\0'; /* truncate off " waiting" */
}
/* Reset ps display if we changed it */
if (new_status)
{
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
pfree(new_status);
}
}
new_status = (char *) palloc(len + 8 + 1);
memcpy(new_status, old_status, len);
strcpy(new_status + len, " waiting");
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
new_status[len] = '\0'; /* truncate off " waiting" */
}
/* Report change to non-waiting status */
if (update_process_title)
{
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
pfree(new_status);
}
/* Report change to non-waiting status */
if (update_process_title)
{
- set_ps_display(new_status, false);
+ set_ps_display(new_status);
pfree(new_status);
}
*/
commandTag = CreateCommandTag(parsetree->stmt);
- set_ps_display(GetCommandTagName(commandTag), false);
+ set_ps_display(GetCommandTagName(commandTag));
BeginCommand(commandTag, dest);
pgstat_report_activity(STATE_RUNNING, query_string);
- set_ps_display("PARSE", false);
+ set_ps_display("PARSE");
if (save_log_statement_stats)
ResetUsage();
pgstat_report_activity(STATE_RUNNING, psrc->query_string);
- set_ps_display("BIND", false);
+ set_ps_display("BIND");
if (save_log_statement_stats)
ResetUsage();
pgstat_report_activity(STATE_RUNNING, sourceText);
- set_ps_display(GetCommandTagName(portal->commandTag), false);
+ set_ps_display(GetCommandTagName(portal->commandTag));
if (save_log_statement_stats)
ResetUsage();
{
if (IsAbortedTransactionBlockState())
{
- set_ps_display("idle in transaction (aborted)", false);
+ set_ps_display("idle in transaction (aborted)");
pgstat_report_activity(STATE_IDLEINTRANSACTION_ABORTED, NULL);
/* Start the idle-in-transaction timer */
}
else if (IsTransactionOrTransactionBlock())
{
- set_ps_display("idle in transaction", false);
+ set_ps_display("idle in transaction");
pgstat_report_activity(STATE_IDLEINTRANSACTION, NULL);
/* Start the idle-in-transaction timer */
pgstat_report_stat(false);
- set_ps_display("idle", false);
+ set_ps_display("idle");
pgstat_report_activity(STATE_IDLE, NULL);
}
/* Report query to various monitoring facilities. */
pgstat_report_activity(STATE_FASTPATH, NULL);
- set_ps_display("", false);
+ set_ps_display("");
/* start an xact for this function invocation */
start_xact_command();
/*
* Now perform authentication exchange.
*/
+ set_ps_display("authentication");
ClientAuthentication(port); /* might not return, if failure */
/*
}
}
- set_ps_display("startup", false);
+ set_ps_display("startup");
ClientAuthInProgress = false; /* client_min_messages is active now */
}
* values. At this point, the original argv[] array may be overwritten.
*/
void
-init_ps_display(const char *username, const char *dbname,
- const char *host_info, const char *initial_str)
+init_ps_display(const char *fixed_part)
{
- Assert(username);
- Assert(dbname);
- Assert(host_info);
+ bool save_update_process_title;
+
+ Assert(fixed_part);
#ifndef PS_USE_NONE
/* no ps display for stand-alone backend */
if (*cluster_name == '\0')
{
snprintf(ps_buffer, ps_buffer_size,
- PROGRAM_NAME_PREFIX "%s %s %s ",
- username, dbname, host_info);
+ PROGRAM_NAME_PREFIX "%s ",
+ fixed_part);
}
else
{
snprintf(ps_buffer, ps_buffer_size,
- PROGRAM_NAME_PREFIX "%s: %s %s %s ",
- cluster_name, username, dbname, host_info);
+ PROGRAM_NAME_PREFIX "%s: %s ",
+ cluster_name, fixed_part);
}
ps_buffer_cur_len = ps_buffer_fixed_size = strlen(ps_buffer);
- set_ps_display(initial_str, true);
+ /*
+ * On the first run, force the update.
+ */
+ save_update_process_title = update_process_title;
+ update_process_title = true;
+ set_ps_display("");
+ update_process_title = save_update_process_title;
#endif /* not PS_USE_NONE */
}
* indication of what you're currently doing passed in the argument.
*/
void
-set_ps_display(const char *activity, bool force)
+set_ps_display(const char *activity)
{
#ifndef PS_USE_NONE
- /* update_process_title=off disables updates, unless force = true */
- if (!force && !update_process_title)
+ /* update_process_title=off disables updates */
+ if (!update_process_title)
return;
/* no ps display for stand-alone backend */
extern char **save_ps_display_args(int argc, char **argv);
-extern void init_ps_display(const char *username, const char *dbname,
- const char *host_info, const char *initial_str);
+extern void init_ps_display(const char *fixed_part);
-extern void set_ps_display(const char *activity, bool force);
+extern void set_ps_display(const char *activity);
extern const char *get_ps_display(int *displen);