mirror of
https://github.com/postgres/postgres.git
synced 2025-12-06 00:02:13 +03:00
Add deadlock counter to pg_stat_database
Adds a counter that tracks number of deadlocks that occurred in each database to pg_stat_database. Magnus Hagander, reviewed by Jaime Casanova
This commit is contained in:
@@ -286,6 +286,7 @@ static void pgstat_recv_bgwriter(PgStat_MsgBgWriter *msg, int len);
|
||||
static void pgstat_recv_funcstat(PgStat_MsgFuncstat *msg, int len);
|
||||
static void pgstat_recv_funcpurge(PgStat_MsgFuncpurge *msg, int len);
|
||||
static void pgstat_recv_recoveryconflict(PgStat_MsgRecoveryConflict *msg, int len);
|
||||
static void pgstat_recv_deadlock(PgStat_MsgDeadlock *msg, int len);
|
||||
static void pgstat_recv_tempfile(PgStat_MsgTempFile *msg, int len);
|
||||
|
||||
|
||||
@@ -1340,6 +1341,24 @@ pgstat_report_recovery_conflict(int reason)
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
}
|
||||
|
||||
/* --------
|
||||
* pgstat_report_deadlock() -
|
||||
*
|
||||
* Tell the collector about a deadlock detected.
|
||||
* --------
|
||||
*/
|
||||
void
|
||||
pgstat_report_deadlock(void)
|
||||
{
|
||||
PgStat_MsgDeadlock msg;
|
||||
|
||||
if (pgStatSock == PGINVALID_SOCKET || !pgstat_track_counts)
|
||||
return;
|
||||
|
||||
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_DEADLOCK);
|
||||
msg.m_databaseid = MyDatabaseId;
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
}
|
||||
|
||||
/* --------
|
||||
* pgstat_report_tempfile() -
|
||||
@@ -1361,7 +1380,6 @@ pgstat_report_tempfile(size_t filesize)
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
/* ----------
|
||||
* pgstat_ping() -
|
||||
@@ -3242,6 +3260,10 @@ PgstatCollectorMain(int argc, char *argv[])
|
||||
pgstat_recv_recoveryconflict((PgStat_MsgRecoveryConflict *) &msg, len);
|
||||
break;
|
||||
|
||||
case PGSTAT_MTYPE_DEADLOCK:
|
||||
pgstat_recv_deadlock((PgStat_MsgDeadlock *) &msg, len);
|
||||
break;
|
||||
|
||||
case PGSTAT_MTYPE_TEMPFILE:
|
||||
pgstat_recv_tempfile((PgStat_MsgTempFile *) &msg, len);
|
||||
break;
|
||||
@@ -3329,6 +3351,7 @@ pgstat_get_db_entry(Oid databaseid, bool create)
|
||||
result->n_conflict_startup_deadlock = 0;
|
||||
result->n_temp_files = 0;
|
||||
result->n_temp_bytes = 0;
|
||||
result->n_deadlocks = 0;
|
||||
|
||||
result->stat_reset_timestamp = GetCurrentTimestamp();
|
||||
|
||||
@@ -4242,6 +4265,7 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
|
||||
dbentry->last_autovac_time = 0;
|
||||
dbentry->n_temp_bytes = 0;
|
||||
dbentry->n_temp_files = 0;
|
||||
dbentry->n_deadlocks = 0;
|
||||
|
||||
dbentry->stat_reset_timestamp = GetCurrentTimestamp();
|
||||
|
||||
@@ -4467,6 +4491,22 @@ pgstat_recv_recoveryconflict(PgStat_MsgRecoveryConflict *msg, int len)
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_recv_deadlock() -
|
||||
*
|
||||
* Process as DEADLOCK message.
|
||||
* ----------
|
||||
*/
|
||||
static void
|
||||
pgstat_recv_deadlock(PgStat_MsgDeadlock *msg, int len)
|
||||
{
|
||||
PgStat_StatDBEntry *dbentry;
|
||||
|
||||
dbentry = pgstat_get_db_entry(msg->m_databaseid, true);
|
||||
|
||||
dbentry->n_deadlocks++;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_recv_tempfile() -
|
||||
*
|
||||
@@ -4482,7 +4522,6 @@ pgstat_recv_tempfile(PgStat_MsgTempFile *msg, int len)
|
||||
|
||||
dbentry->n_temp_bytes += msg->m_filesize;
|
||||
dbentry->n_temp_files += 1;
|
||||
|
||||
}
|
||||
|
||||
/* ----------
|
||||
|
||||
Reference in New Issue
Block a user