2022-03-21 20:02:25 +01:00
|
|
|
/* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pgstat_replslot.c
|
|
|
|
* Implementation of replication slot statistics.
|
|
|
|
*
|
|
|
|
* This file contains the implementation of replication slot statistics. It is kept
|
|
|
|
* separate from pgstat.c to enforce the line between the statistics access /
|
|
|
|
* storage implementation and the details about individual types of
|
|
|
|
* statistics.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2001-2022, PostgreSQL Global Development Group
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/backend/utils/activity/pgstat_replslot.c
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "replication/slot.h"
|
|
|
|
#include "utils/builtins.h" /* for namestrcpy() */
|
|
|
|
#include "utils/pgstat_internal.h"
|
|
|
|
|
|
|
|
|
2022-04-04 21:14:34 +02:00
|
|
|
/*
|
2022-04-07 02:56:19 +02:00
|
|
|
* Reset counters for a single replication slot.
|
2022-03-21 20:02:25 +01:00
|
|
|
*
|
2022-04-04 21:14:34 +02:00
|
|
|
* Permission checking for this function is managed through the normal
|
|
|
|
* GRANT system.
|
2022-03-21 20:02:25 +01:00
|
|
|
*/
|
|
|
|
void
|
2022-04-07 02:56:19 +02:00
|
|
|
pgstat_reset_replslot(const char *name)
|
2022-03-21 20:02:25 +01:00
|
|
|
{
|
2022-04-07 02:56:19 +02:00
|
|
|
ReplicationSlot *slot;
|
2022-03-21 20:02:25 +01:00
|
|
|
PgStat_MsgResetreplslotcounter msg;
|
|
|
|
|
2022-04-07 02:56:19 +02:00
|
|
|
AssertArg(name != NULL);
|
|
|
|
|
2022-03-21 20:02:25 +01:00
|
|
|
if (pgStatSock == PGINVALID_SOCKET)
|
|
|
|
return;
|
|
|
|
|
2022-04-07 02:56:19 +02:00
|
|
|
/*
|
|
|
|
* Check if the slot exists with the given name. It is possible that by
|
|
|
|
* the time this message is executed the slot is dropped but at least this
|
|
|
|
* check will ensure that the given name is for a valid slot.
|
|
|
|
*/
|
|
|
|
slot = SearchNamedReplicationSlot(name, true);
|
2022-03-21 20:02:25 +01:00
|
|
|
|
2022-04-07 02:56:19 +02:00
|
|
|
if (!slot)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
|
|
|
errmsg("replication slot \"%s\" does not exist",
|
|
|
|
name)));
|
2022-03-21 20:02:25 +01:00
|
|
|
|
2022-04-07 02:56:19 +02:00
|
|
|
/*
|
|
|
|
* Nothing to do for physical slots as we collect stats only for logical
|
|
|
|
* slots.
|
|
|
|
*/
|
|
|
|
if (SlotIsPhysical(slot))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETREPLSLOTCOUNTER);
|
|
|
|
namestrcpy(&msg.m_slotname, name);
|
|
|
|
msg.clearall = false;
|
2022-03-21 20:02:25 +01:00
|
|
|
pgstat_send(&msg, sizeof(msg));
|
|
|
|
}
|
|
|
|
|
2022-04-04 21:14:34 +02:00
|
|
|
/*
|
2022-04-06 22:56:06 +02:00
|
|
|
* Report replication slot statistics.
|
2022-03-21 20:02:25 +01:00
|
|
|
*/
|
|
|
|
void
|
2022-04-07 03:26:17 +02:00
|
|
|
pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *repSlotStat)
|
2022-03-21 20:02:25 +01:00
|
|
|
{
|
|
|
|
PgStat_MsgReplSlot msg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare and send the message
|
|
|
|
*/
|
|
|
|
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
|
|
|
|
namestrcpy(&msg.m_slotname, NameStr(repSlotStat->slotname));
|
|
|
|
msg.m_create = false;
|
|
|
|
msg.m_drop = false;
|
|
|
|
msg.m_spill_txns = repSlotStat->spill_txns;
|
|
|
|
msg.m_spill_count = repSlotStat->spill_count;
|
|
|
|
msg.m_spill_bytes = repSlotStat->spill_bytes;
|
|
|
|
msg.m_stream_txns = repSlotStat->stream_txns;
|
|
|
|
msg.m_stream_count = repSlotStat->stream_count;
|
|
|
|
msg.m_stream_bytes = repSlotStat->stream_bytes;
|
|
|
|
msg.m_total_txns = repSlotStat->total_txns;
|
|
|
|
msg.m_total_bytes = repSlotStat->total_bytes;
|
|
|
|
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
|
|
|
|
}
|
|
|
|
|
2022-04-04 21:14:34 +02:00
|
|
|
/*
|
2022-04-06 22:56:06 +02:00
|
|
|
* Report replication slot creation.
|
2022-04-07 03:26:17 +02:00
|
|
|
*
|
|
|
|
* NB: This gets called with ReplicationSlotAllocationLock already held, be
|
|
|
|
* careful about calling back into slot.c.
|
2022-03-21 20:02:25 +01:00
|
|
|
*/
|
|
|
|
void
|
2022-04-07 03:26:17 +02:00
|
|
|
pgstat_create_replslot(ReplicationSlot *slot)
|
2022-03-21 20:02:25 +01:00
|
|
|
{
|
|
|
|
PgStat_MsgReplSlot msg;
|
|
|
|
|
|
|
|
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
|
2022-04-07 03:26:17 +02:00
|
|
|
namestrcpy(&msg.m_slotname, NameStr(slot->data.name));
|
2022-03-21 20:02:25 +01:00
|
|
|
msg.m_create = true;
|
|
|
|
msg.m_drop = false;
|
|
|
|
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
|
|
|
|
}
|
|
|
|
|
2022-04-04 21:14:34 +02:00
|
|
|
/*
|
2022-04-06 22:56:06 +02:00
|
|
|
* Report replication slot drop.
|
2022-03-21 20:02:25 +01:00
|
|
|
*/
|
|
|
|
void
|
2022-04-07 03:26:17 +02:00
|
|
|
pgstat_drop_replslot(ReplicationSlot *slot)
|
2022-03-21 20:02:25 +01:00
|
|
|
{
|
|
|
|
PgStat_MsgReplSlot msg;
|
|
|
|
|
|
|
|
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
|
2022-04-07 03:26:17 +02:00
|
|
|
namestrcpy(&msg.m_slotname, NameStr(slot->data.name));
|
2022-03-21 20:02:25 +01:00
|
|
|
msg.m_create = false;
|
|
|
|
msg.m_drop = true;
|
|
|
|
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
|
|
|
|
}
|