aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/pgstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
-rw-r--r--src/backend/postmaster/pgstat.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 3b7aa07014d..84d790a3faf 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -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();
@@ -4468,6 +4492,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() -
*
* Process as PGSTAT_MTYPE_TEMPFILE message.
@@ -4482,7 +4522,6 @@ pgstat_recv_tempfile(PgStat_MsgTempFile *msg, int len)
dbentry->n_temp_bytes += msg->m_filesize;
dbentry->n_temp_files += 1;
-
}
/* ----------