mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Add a 'waiting' column to pg_stat_activity to carry the same information
that ps_status provides by appending 'waiting' to the PS display. This completes the project of making it feasible to turn off process title updates and instead rely on pg_stat_activity. Per my suggestion a few weeks ago.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.29 2006/07/27 08:30:41 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.30 2006/08/19 01:36:24 tgl Exp $
|
||||
*/
|
||||
|
||||
CREATE VIEW pg_roles AS
|
||||
@@ -332,7 +332,8 @@ CREATE VIEW pg_stat_activity AS
|
||||
pg_stat_get_backend_pid(S.backendid) AS procpid,
|
||||
pg_stat_get_backend_userid(S.backendid) AS usesysid,
|
||||
U.rolname AS usename,
|
||||
pg_stat_get_backend_activity(S.backendid) AS current_query,
|
||||
pg_stat_get_backend_activity(S.backendid) AS current_query,
|
||||
pg_stat_get_backend_waiting(S.backendid) AS waiting,
|
||||
pg_stat_get_backend_activity_start(S.backendid) AS query_start,
|
||||
pg_stat_get_backend_start(S.backendid) AS backend_start,
|
||||
pg_stat_get_backend_client_addr(S.backendid) AS client_addr,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
* Copyright (c) 2001-2006, PostgreSQL Global Development Group
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.136 2006/07/16 18:17:14 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.137 2006/08/19 01:36:24 tgl Exp $
|
||||
* ----------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@@ -1358,6 +1358,7 @@ pgstat_bestart(void)
|
||||
beentry->st_databaseid = MyDatabaseId;
|
||||
beentry->st_userid = userid;
|
||||
beentry->st_clientaddr = clientaddr;
|
||||
beentry->st_waiting = false;
|
||||
beentry->st_activity[0] = '\0';
|
||||
/* Also make sure the last byte in the string area is always 0 */
|
||||
beentry->st_activity[PGBE_ACTIVITY_SIZE - 1] = '\0';
|
||||
@@ -1445,6 +1446,31 @@ pgstat_report_activity(const char *cmd_str)
|
||||
}
|
||||
|
||||
|
||||
/* ----------
|
||||
* pgstat_report_waiting() -
|
||||
*
|
||||
* Called from lock manager to report beginning or end of a lock wait.
|
||||
* ----------
|
||||
*/
|
||||
void
|
||||
pgstat_report_waiting(bool waiting)
|
||||
{
|
||||
volatile PgBackendStatus *beentry;
|
||||
|
||||
if (!pgstat_collect_querystring)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Since this is a single-byte field in a struct that only this process
|
||||
* may modify, there seems no need to bother with the st_changecount
|
||||
* protocol. The update must appear atomic in any case.
|
||||
*/
|
||||
beentry = MyBEEntry;
|
||||
|
||||
beentry->st_waiting = waiting;
|
||||
}
|
||||
|
||||
|
||||
/* ----------
|
||||
* pgstat_read_current_status() -
|
||||
*
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.170 2006/07/31 20:09:05 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.171 2006/08/19 01:36:28 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* A lock table is a shared memory hash table. When
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "access/twophase.h"
|
||||
#include "access/twophase_rmgr.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/lmgr.h"
|
||||
#include "utils/memutils.h"
|
||||
#include "utils/ps_status.h"
|
||||
@@ -1114,6 +1115,7 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
|
||||
LOCK_PRINT("WaitOnLock: sleeping on lock",
|
||||
locallock->lock, locallock->tag.mode);
|
||||
|
||||
/* Report change to waiting status */
|
||||
if (update_process_title)
|
||||
{
|
||||
old_status = get_ps_display(&len);
|
||||
@@ -1123,7 +1125,8 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
|
||||
set_ps_display(new_status, false);
|
||||
new_status[len] = '\0'; /* truncate off " waiting" */
|
||||
}
|
||||
|
||||
pgstat_report_waiting(true);
|
||||
|
||||
awaitedLock = locallock;
|
||||
awaitedOwner = owner;
|
||||
|
||||
@@ -1160,11 +1163,13 @@ WaitOnLock(LOCALLOCK *locallock, ResourceOwner owner)
|
||||
|
||||
awaitedLock = NULL;
|
||||
|
||||
/* Report change to non-waiting status */
|
||||
if (update_process_title)
|
||||
{
|
||||
set_ps_display(new_status, false);
|
||||
pfree(new_status);
|
||||
}
|
||||
pgstat_report_waiting(false);
|
||||
|
||||
LOCK_PRINT("WaitOnLock: wakeup on lock",
|
||||
locallock->lock, locallock->tag.mode);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.32 2006/07/14 14:52:24 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.33 2006/08/19 01:36:29 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,6 +42,7 @@ extern Datum pg_stat_get_backend_pid(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_waiting(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_start(PG_FUNCTION_ARGS);
|
||||
extern Datum pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS);
|
||||
@@ -377,6 +378,25 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
pg_stat_get_backend_waiting(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int32 beid = PG_GETARG_INT32(0);
|
||||
bool result;
|
||||
PgBackendStatus *beentry;
|
||||
|
||||
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
if (!superuser() && beentry->st_userid != GetUserId())
|
||||
PG_RETURN_NULL();
|
||||
|
||||
result = beentry->st_waiting;
|
||||
|
||||
PG_RETURN_BOOL(result);
|
||||
}
|
||||
|
||||
|
||||
Datum
|
||||
pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user