Skip to content

Commit fc70a4b

Browse files
committed
Show more processes in pg_stat_activity.
Previously, auxiliary processes and background workers not connected to a database (such as the logical replication launcher) weren't shown. Include them, so that we can see the associated wait state information. Add a new column to identify the processes type, so that people can filter them out easily using SQL if they wish. Before this patch was written, there was discussion about whether we should expose this information in a separate view, so as to avoid contaminating pg_stat_activity with things people might not want to see. But putting everything in pg_stat_activity was a more popular choice, so that's what the patch does. Kuntal Ghosh, reviewed by Amit Langote and Michael Paquier. Some revisions and bug fixes by me. Discussion: http://postgr.es/m/CA+TgmoYES5nhkEGw9nZXU8_FhA8XEm8NTm3-SO+3ML1B81Hkww@mail.gmail.com
1 parent 2f0903e commit fc70a4b

File tree

14 files changed

+305
-53
lines changed

14 files changed

+305
-53
lines changed

doc/src/sgml/monitoring.sgml

+13-2
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
620620
<row>
621621
<entry><structfield>backend_start</></entry>
622622
<entry><type>timestamp with time zone</></entry>
623-
<entry>Time when this process was started, i.e., when the
624-
client connected to the server
623+
<entry>Time when this process was started. For client backends,
624+
this is the time the client connected to the server.
625625
</entry>
626626
</row>
627627
<row>
@@ -797,6 +797,17 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
797797
<xref linkend="guc-track-activity-query-size">.
798798
</entry>
799799
</row>
800+
<row>
801+
<entry><structfield>backend_type</structfield></entry>
802+
<entry><type>text</type></entry>
803+
<entry>Type of current backend. Possible types are
804+
<literal>autovacuum launcher</>, <literal>autovacuum worker</>,
805+
<literal>background worker</>, <literal>background writer</>,
806+
<literal>client backend</>, <literal>checkpointer</>,
807+
<literal>startup</>, <literal>walreceiver</>,
808+
<literal>walsender</> and <literal>walwriter</>.
809+
</entry>
810+
</row>
800811
</tbody>
801812
</tgroup>
802813
</table>

src/backend/bootstrap/bootstrap.c

+4
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ AuxiliaryProcessMain(int argc, char *argv[])
387387
/* finish setting up bufmgr.c */
388388
InitBufferPoolBackend();
389389

390+
/* Initialize backend status information */
391+
pgstat_initialize();
392+
pgstat_bestart();
393+
390394
/* register a before-shutdown callback for LWLock cleanup */
391395
before_shmem_exit(ShutdownAuxiliaryProcess, 0);
392396
}

src/backend/catalog/system_views.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,8 @@ CREATE VIEW pg_stat_activity AS
716716
S.state,
717717
S.backend_xid,
718718
s.backend_xmin,
719-
S.query
719+
S.query,
720+
S.backend_type
720721
FROM pg_stat_get_activity(NULL) AS S
721722
LEFT JOIN pg_database AS D ON (S.datid = D.oid)
722723
LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid);

0 commit comments

Comments
 (0)