mirror of
https://github.com/postgres/postgres.git
synced 2025-07-11 10:01:57 +03:00
Collect statistics about SLRU caches
There's a number of SLRU caches used to access important data like clog, commit timestamps, multixact, asynchronous notifications, etc. Until now we had no easy way to monitor these shared caches, compute hit ratios, number of reads/writes etc. This commit extends the statistics collector to track this information for a predefined list of SLRUs, and also introduces a new system view pg_stat_slru displaying the data. The list of built-in SLRUs is fixed, but additional SLRUs may be defined in extensions. Unfortunately, there's no suitable registry of SLRUs, so this patch simply defines a fixed list of SLRUs with entries for the built-in ones and one entry for all additional SLRUs. Extensions adding their own SLRU are fairly rare, so this seems acceptable. This patch only allows monitoring of SLRUs, not tuning. The SLRU sizes are still fixed (hard-coded in the code) and it's not entirely clear which of the SLRUs might need a GUC to tune size. In a way, allowing us to determine that is one of the goals of this patch. Bump catversion as the patch introduces new functions and system view. Author: Tomas Vondra Reviewed-by: Alvaro Herrera Discussion: https://www.postgresql.org/message-id/flat/20200119143707.gyinppnigokesjok@development
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#ifndef PGSTAT_H
|
||||
#define PGSTAT_H
|
||||
|
||||
#include "access/slru.h"
|
||||
#include "datatype/timestamp.h"
|
||||
#include "libpq/pqcomm.h"
|
||||
#include "miscadmin.h"
|
||||
@ -55,11 +56,13 @@ typedef enum StatMsgType
|
||||
PGSTAT_MTYPE_RESETCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSHAREDCOUNTER,
|
||||
PGSTAT_MTYPE_RESETSINGLECOUNTER,
|
||||
PGSTAT_MTYPE_RESETSLRUCOUNTER,
|
||||
PGSTAT_MTYPE_AUTOVAC_START,
|
||||
PGSTAT_MTYPE_VACUUM,
|
||||
PGSTAT_MTYPE_ANALYZE,
|
||||
PGSTAT_MTYPE_ARCHIVER,
|
||||
PGSTAT_MTYPE_BGWRITER,
|
||||
PGSTAT_MTYPE_SLRU,
|
||||
PGSTAT_MTYPE_FUNCSTAT,
|
||||
PGSTAT_MTYPE_FUNCPURGE,
|
||||
PGSTAT_MTYPE_RECOVERYCONFLICT,
|
||||
@ -343,6 +346,17 @@ typedef struct PgStat_MsgResetsinglecounter
|
||||
Oid m_objectid;
|
||||
} PgStat_MsgResetsinglecounter;
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgResetslrucounter Sent by the backend to tell the collector
|
||||
* to reset a SLRU counter
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_MsgResetslrucounter
|
||||
{
|
||||
PgStat_MsgHdr m_hdr;
|
||||
int m_index;
|
||||
} PgStat_MsgResetslrucounter;
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgAutovacStart Sent by the autovacuum daemon to signal
|
||||
* that a database is going to be processed
|
||||
@ -423,6 +437,23 @@ typedef struct PgStat_MsgBgWriter
|
||||
PgStat_Counter m_checkpoint_sync_time;
|
||||
} PgStat_MsgBgWriter;
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgSLRU Sent by the SLRU to update statistics.
|
||||
* ----------
|
||||
*/
|
||||
typedef struct PgStat_MsgSLRU
|
||||
{
|
||||
PgStat_MsgHdr m_hdr;
|
||||
PgStat_Counter m_index;
|
||||
PgStat_Counter m_blocks_zeroed;
|
||||
PgStat_Counter m_blocks_hit;
|
||||
PgStat_Counter m_blocks_read;
|
||||
PgStat_Counter m_blocks_written;
|
||||
PgStat_Counter m_blocks_exists;
|
||||
PgStat_Counter m_flush;
|
||||
PgStat_Counter m_truncate;
|
||||
} PgStat_MsgSLRU;
|
||||
|
||||
/* ----------
|
||||
* PgStat_MsgRecoveryConflict Sent by the backend upon recovery conflict
|
||||
* ----------
|
||||
@ -560,11 +591,13 @@ typedef union PgStat_Msg
|
||||
PgStat_MsgResetcounter msg_resetcounter;
|
||||
PgStat_MsgResetsharedcounter msg_resetsharedcounter;
|
||||
PgStat_MsgResetsinglecounter msg_resetsinglecounter;
|
||||
PgStat_MsgResetslrucounter msg_resetslrucounter;
|
||||
PgStat_MsgAutovacStart msg_autovacuum_start;
|
||||
PgStat_MsgVacuum msg_vacuum;
|
||||
PgStat_MsgAnalyze msg_analyze;
|
||||
PgStat_MsgArchiver msg_archiver;
|
||||
PgStat_MsgBgWriter msg_bgwriter;
|
||||
PgStat_MsgSLRU msg_slru;
|
||||
PgStat_MsgFuncstat msg_funcstat;
|
||||
PgStat_MsgFuncpurge msg_funcpurge;
|
||||
PgStat_MsgRecoveryConflict msg_recoveryconflict;
|
||||
@ -713,6 +746,21 @@ typedef struct PgStat_GlobalStats
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_GlobalStats;
|
||||
|
||||
/*
|
||||
* SLRU statistics kept in the stats collector
|
||||
*/
|
||||
typedef struct PgStat_SLRUStats
|
||||
{
|
||||
PgStat_Counter blocks_zeroed;
|
||||
PgStat_Counter blocks_hit;
|
||||
PgStat_Counter blocks_read;
|
||||
PgStat_Counter blocks_written;
|
||||
PgStat_Counter blocks_exists;
|
||||
PgStat_Counter flush;
|
||||
PgStat_Counter truncate;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_SLRUStats;
|
||||
|
||||
|
||||
/* ----------
|
||||
* Backend states
|
||||
@ -1210,6 +1258,11 @@ extern char *pgstat_stat_filename;
|
||||
*/
|
||||
extern PgStat_MsgBgWriter BgWriterStats;
|
||||
|
||||
/*
|
||||
* SLRU statistics counters are updated directly by slru.
|
||||
*/
|
||||
extern PgStat_MsgSLRU SlruStats[];
|
||||
|
||||
/*
|
||||
* Updated by pgstat_count_buffer_*_time macros
|
||||
*/
|
||||
@ -1247,6 +1300,7 @@ extern void pgstat_clear_snapshot(void);
|
||||
extern void pgstat_reset_counters(void);
|
||||
extern void pgstat_reset_shared_counters(const char *);
|
||||
extern void pgstat_reset_single_counter(Oid objectid, PgStat_Single_Reset_Type type);
|
||||
extern void pgstat_reset_slru_counter(const char *);
|
||||
|
||||
extern void pgstat_report_autovac(Oid dboid);
|
||||
extern void pgstat_report_vacuum(Oid tableoid, bool shared,
|
||||
@ -1422,5 +1476,16 @@ extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid);
|
||||
extern int pgstat_fetch_stat_numbackends(void);
|
||||
extern PgStat_ArchiverStats *pgstat_fetch_stat_archiver(void);
|
||||
extern PgStat_GlobalStats *pgstat_fetch_global(void);
|
||||
extern PgStat_SLRUStats *pgstat_fetch_slru(void);
|
||||
|
||||
extern void pgstat_count_slru_page_zeroed(SlruCtl ctl);
|
||||
extern void pgstat_count_slru_page_hit(SlruCtl ctl);
|
||||
extern void pgstat_count_slru_page_read(SlruCtl ctl);
|
||||
extern void pgstat_count_slru_page_written(SlruCtl ctl);
|
||||
extern void pgstat_count_slru_page_exists(SlruCtl ctl);
|
||||
extern void pgstat_count_slru_flush(SlruCtl ctl);
|
||||
extern void pgstat_count_slru_truncate(SlruCtl ctl);
|
||||
extern char *pgstat_slru_name(int idx);
|
||||
extern int pgstat_slru_index(const char *name);
|
||||
|
||||
#endif /* PGSTAT_H */
|
||||
|
Reference in New Issue
Block a user