From aacedd4fca9dc52367a250c67459605849c7291e Mon Sep 17 00:00:00 2001 From: Kuntal Ghosh Date: Thu, 23 Mar 2017 16:39:05 +0530 Subject: [PATCH 2/3] Expose stats for all backends All backends include auxiliary procs, autovacuum launcher and bgworkers having valid BackendIds. --- src/backend/bootstrap/bootstrap.c | 3 +++ src/backend/postmaster/autovacuum.c | 3 +++ src/backend/postmaster/bgwriter.c | 3 +++ src/backend/postmaster/checkpointer.c | 3 +++ src/backend/postmaster/pgstat.c | 1 - src/backend/postmaster/postmaster.c | 6 ++++++ src/backend/postmaster/startup.c | 4 ++++ src/backend/postmaster/walwriter.c | 3 +++ src/backend/replication/walreceiver.c | 4 ++++ src/backend/replication/walsender.c | 5 ++++- src/backend/utils/init/postinit.c | 3 --- 11 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 6511c60..f56e229 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -387,6 +387,9 @@ AuxiliaryProcessMain(int argc, char *argv[]) /* finish setting up bufmgr.c */ InitBufferPoolBackend(); + /* Initialize stats collection */ + pgstat_initialize(); + /* register a before-shutdown callback for LWLock cleanup */ before_shmem_exit(ShutdownAuxiliaryProcess, 0); } diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 33ca749..0dd8ccc 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -453,6 +453,9 @@ AutoVacLauncherMain(int argc, char *argv[]) InitPostgres(NULL, InvalidOid, NULL, InvalidOid, NULL); + /* report autovacuum launcher process in the PgBackendStatus array */ + pgstat_bestart(); + SetProcessingMode(NormalProcessing); /* diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index dcb4cf2..6ba2e2e 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -248,6 +248,9 @@ BackgroundWriterMain(void) */ prev_hibernate = false; + /* report bgwriter process in the PgBackendStatus array */ + pgstat_bestart(); + /* * Loop forever */ diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index fe9041f..8eb0a2a 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -345,6 +345,9 @@ CheckpointerMain(void) */ ProcGlobal->checkpointerLatch = &MyProc->procLatch; + /* report checkpointer process in the PgBackendStatus array */ + pgstat_bestart(); + /* * Loop forever */ diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index a2b9bbf..ff565a3 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -2690,7 +2690,6 @@ pgstat_initialize(void) * pgstat_bestart() - * * Initialize this backend's entry in the PgBackendStatus array. - * Called from InitPostgres. * * Apart from auxiliary processes, MyBackendId, MyDatabaseId, * session userid, and application_name must be set for a diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 6831342..4f62b99 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -5461,6 +5461,9 @@ BackgroundWorkerInitializeConnection(char *dbname, char *username) InitPostgres(dbname, InvalidOid, username, InvalidOid, NULL); + /* report the parallel worker process in the PgBackendStatus array */ + pgstat_bestart(); + /* it had better not gotten out of "init" mode yet */ if (!IsInitProcessingMode()) ereport(ERROR, @@ -5484,6 +5487,9 @@ BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid) InitPostgres(NULL, dboid, NULL, useroid, NULL); + /* report the parallel worker process in the PgBackendStatus array */ + pgstat_bestart(); + /* it had better not gotten out of "init" mode yet */ if (!IsInitProcessingMode()) ereport(ERROR, diff --git a/src/backend/postmaster/startup.c b/src/backend/postmaster/startup.c index b172b5e..56ff042 100644 --- a/src/backend/postmaster/startup.c +++ b/src/backend/postmaster/startup.c @@ -25,6 +25,7 @@ #include "access/xlog.h" #include "libpq/pqsignal.h" #include "miscadmin.h" +#include "pgstat.h" #include "postmaster/startup.h" #include "storage/ipc.h" #include "storage/latch.h" @@ -210,6 +211,9 @@ StartupProcessMain(void) */ PG_SETMASK(&UnBlockSig); + /* report startup process in the PgBackendStatus array */ + pgstat_bestart(); + /* * Do what we came for. */ diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index a575d8f..9056652 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -231,6 +231,9 @@ WalWriterMain(void) */ ProcGlobal->walwriterLatch = &MyProc->procLatch; + /* report walwriter process in the PgBackendStatus array */ + pgstat_bestart(); + /* * Loop forever */ diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index 31c567b..cdd35e2 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -316,6 +316,10 @@ WalReceiverMain(void) SpinLockRelease(&walrcv->mutex); first_stream = true; + + /* report walreceiver process in the PgBackendStatus array */ + pgstat_bestart(); + for (;;) { char *primary_sysid; diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 7561770..f79d4a5 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -246,6 +246,9 @@ InitWalSender(void) */ MarkPostmasterChildWalSender(); SendPostmasterSignal(PMSIGNAL_ADVANCE_STATE_MACHINE); + + /* report walsender process in the PgBackendStatus array */ + pgstat_bestart(); } /* @@ -1811,7 +1814,7 @@ WalSndLoop(WalSndSendDataCallback send_data) waiting_for_ping_response = false; /* Report to pgstat that this process is a WAL sender */ - pgstat_report_activity(STATE_RUNNING, "walsender"); + pgstat_report_activity(STATE_RUNNING, NULL); /* * Loop until we reach the end of this timeline or the client requests to diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index 9f938f2..2470f24 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -808,9 +808,6 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, /* initialize client encoding */ InitializeClientEncoding(); - /* report this backend in the PgBackendStatus array */ - pgstat_bestart(); - /* close the transaction we started above */ CommitTransactionCommand(); -- 1.8.3.1