diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 649cef8..f52bc59 100644 *** a/src/backend/catalog/system_views.sql --- b/src/backend/catalog/system_views.sql *************** *** 664,670 **** CREATE VIEW pg_stat_activity AS S.state, S.backend_xid, s.backend_xmin, ! S.query FROM pg_stat_get_activity(NULL) AS S LEFT JOIN pg_database AS D ON (S.datid = D.oid) LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid); --- 664,671 ---- S.state, S.backend_xid, s.backend_xmin, ! S.query, ! S.wait_start FROM pg_stat_get_activity(NULL) AS S LEFT JOIN pg_database AS D ON (S.datid = D.oid) LEFT JOIN pg_authid AS U ON (S.usesysid = U.oid); diff --git a/src/backend/postmaster/pgstat.index 61e6a2c..fb855f2 100644 *** a/src/backend/postmaster/pgstat.c --- b/src/backend/postmaster/pgstat.c *************** *** 2833,2838 **** pgstat_report_activity(BackendState state, const char *cmd_str) --- 2833,2839 ---- /* st_xact_start_timestamp and wait_event_info are also disabled */ beentry->st_xact_start_timestamp = 0; proc->wait_event_info = 0; + proc->wait_start = 0; pgstat_increment_changecount_after(beentry); } return; diff --git a/src/backend/storage/lmgr/index e9555f2..8db2c52 100644 *** a/src/backend/storage/lmgr/proc.c --- b/src/backend/storage/lmgr/proc.c *************** *** 406,411 **** InitProcess(void) --- 406,412 ---- /* Initialize wait event information. */ MyProc->wait_event_info = 0; + MyProc->wait_start = 0; /* * Acquire ownership of the PGPROC's latch, so that we can use WaitLatch diff --git a/src/backend/utils/adt/pgsindex 2d3cf9e..dbb4605 100644 *** a/src/backend/utils/adt/pgstatfuncs.c --- b/src/backend/utils/adt/pgstatfuncs.c *************** *** 638,644 **** pg_stat_get_progress_info(PG_FUNCTION_ARGS) Datum pg_stat_get_activity(PG_FUNCTION_ARGS) { ! #define PG_STAT_GET_ACTIVITY_COLS 23 int num_backends = pgstat_fetch_stat_numbackends(); int curr_backend; int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0); --- 638,644 ---- Datum pg_stat_get_activity(PG_FUNCTION_ARGS) { ! #define PG_STAT_GET_ACTIVITY_COLS 24 int num_backends = pgstat_fetch_stat_numbackends(); int curr_backend; int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0); *************** *** 806,811 **** pg_stat_get_activity(PG_FUNCTION_ARGS) --- 806,816 ---- else nulls[7] = true; + if (proc->wait_start) + values[23] = TimestampTzGetDatum(time_t_to_timestamptz(proc->wait_start)); + else + nulls[23] = true; + if (beentry->st_xact_start_timestamp != 0) values[8] = TimestampTzGetDatum(beentry->st_xact_start_timestamp); else diff --git a/src/include/catalog/pg_proc.hindex cd7b909..eee9e31 100644 *** a/src/include/catalog/pg_proc.h --- b/src/include/catalog/pg_proc.h *************** *** 2764,2770 **** DATA(insert OID = 3057 ( pg_stat_get_autoanalyze_count PGNSP PGUID 12 1 0 0 0 f DESCR("statistics: number of auto analyzes for a table"); DATA(insert OID = 1936 ( pg_stat_get_backend_idset PGNSP PGUID 12 1 100 0 0 f f f f t t s r 0 0 23 "" _null_ _null_ _null_ _null_ _null_ pg_stat_get_backend_idset _null_ _null_ _null_ )); DESCR("statistics: currently active backend IDs"); ! DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 0 f f f f f t s r 1 0 2249 "23" "{23,26,23,26,25,25,25,25,25,1184,1184,1184,1184,869,25,23,28,28,16,25,25,23,16,25}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,pid,usesysid,application_name,state,query,wait_event_type,wait_event,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,backend_xid,backend_xmin,ssl,sslversion,sslcipher,sslbits,sslcompression,sslclientdn}" _null_ _null_ pg_stat_get_activity _null_ _null_ _null_ )); DESCR("statistics: information about currently active backends"); DATA(insert OID = 3318 ( pg_stat_get_progress_info PGNSP PGUID 12 1 100 0 0 f f f f t t s r 1 0 2249 "25" "{25,23,26,26,20,20,20,20,20,20,20,20,20,20}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{cmdtype,pid,datid,relid,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10}" _null_ _null_ pg_stat_get_progress_info _null_ _null_ _null_ )); DESCR("statistics: information about progress of backends running maintenance command"); --- 2764,2770 ---- DESCR("statistics: number of auto analyzes for a table"); DATA(insert OID = 1936 ( pg_stat_get_backend_idset PGNSP PGUID 12 1 100 0 0 f f f f t t s r 0 0 23 "" _null_ _null_ _null_ _null_ _null_ pg_stat_get_backend_idset _null_ _null_ _null_ )); DESCR("statistics: currently active backend IDs"); ! DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 0 f f f f f t s r 1 0 2249 "23" "{23,26,23,26,25,25,25,25,25,1184,1184,1184,1184,869,25,23,28,28,16,25,25,23,16,25,1184}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,pid,usesysid,application_name,state,query,wait_event_type,wait_event,xact_start,query_start,backend_start,state_change,client_addr,client_hostname,client_port,backend_xid,backend_xmin,ssl,sslversion,sslcipher,sslbits,sslcompression,sslclientdn,wait_start}" _null_ _null_ pg_stat_get_activity _null_ _null_ _null_ )); DESCR("statistics: information about currently active backends"); DATA(insert OID = 3318 ( pg_stat_get_progress_info PGNSP PGUID 12 1 100 0 0 f f f f t t s r 1 0 2249 "25" "{25,23,26,26,20,20,20,20,20,20,20,20,20,20}" "{i,o,o,o,o,o,o,o,o,o,o,o,o,o}" "{cmdtype,pid,datid,relid,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10}" _null_ _null_ pg_stat_get_progress_info _null_ _null_ _null_ )); DESCR("statistics: information about progress of backends running maintenance command"); diff --git a/src/include/pgstat.h b/index 282f8ae..009055c 100644 *** a/src/include/pgstat.h --- b/src/include/pgstat.h *************** *** 20,26 **** #include "storage/proc.h" #include "utils/hsearch.h" #include "utils/relcache.h" ! /* ---------- * Paths for the statistics files (relative to installation's $PGDATA). --- 20,26 ---- #include "storage/proc.h" #include "utils/hsearch.h" #include "utils/relcache.h" ! #include "pgtime.h" /* ---------- * Paths for the statistics files (relative to installation's $PGDATA). *************** *** 1106,1111 **** pgstat_report_wait_start(uint32 wait_event_info) --- 1106,1114 ---- * four-bytes, updates are atomic. */ proc->wait_event_info = wait_event_info; + + if (proc->wait_start == 0) + proc->wait_start = (pg_time_t) time(NULL); } /* ---------- *************** *** 1130,1135 **** pgstat_report_wait_end(void) --- 1133,1139 ---- * four-bytes, updates are atomic. */ proc->wait_event_info = 0; + proc->wait_start = 0; } /* nontransactional event counts are simple enough to inline */ diff --git a/src/include/stindex 0344f42..c259a1b 100644 *** a/src/include/storage/proc.h --- b/src/include/storage/proc.h *************** *** 20,25 **** --- 20,26 ---- #include "storage/lock.h" #include "storage/pg_sema.h" #include "storage/proclist_types.h" + #include "pgtime.h" /* * Each backend advertises up to PGPROC_MAX_CACHED_SUBXIDS TransactionIds *************** *** 176,181 **** struct PGPROC --- 177,184 ---- PGPROC *lockGroupLeader; /* lock group leader, if I'm a member */ dlist_head lockGroupMembers; /* list of members, if I'm a leader */ dlist_node lockGroupLink; /* my member link, if I'm a member */ + + pg_time_t wait_start; /* time when the proc started waiting */ }; /* NOTE: "typedef struct PGPROC PGPROC" appears in storage/lock.h. */