=== Applying patches on top of PostgreSQL commit ID 53a49365052026907afff7613929710d1e7f0da0 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sat Feb 1 03:24:28 UTC 2025 On branch cf/5007 nothing to commit, working tree clean === applying patch ./v6-0001-Clear-padding-in-PgStat_HashKey-keys.patch Applied patch to 'src/backend/utils/activity/pgstat.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_shmem.c' cleanly. [cf/5007 3417804337] Clear padding in PgStat_HashKey keys Author: Bertrand Drouvot Date: Sat Nov 2 14:21:18 2024 +0000 === applying patch ./v6-0002-Provide-relfilenode-statistics.patch Applied patch to 'src/backend/access/rmgrdesc/xactdesc.c' cleanly. Applied patch to 'src/backend/catalog/storage.c' cleanly. Applied patch to 'src/backend/catalog/system_functions.sql' cleanly. Applied patch to 'src/backend/catalog/system_views.sql' cleanly. Applied patch to 'src/backend/postmaster/checkpointer.c' cleanly. Applied patch to 'src/backend/storage/buffer/bufmgr.c' cleanly. Applied patch to 'src/backend/storage/smgr/md.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat.c' with conflicts. Applied patch to 'src/backend/utils/activity/pgstat_database.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_function.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_relation.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_replslot.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_shmem.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_subscription.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_xact.c' cleanly. Applied patch to 'src/backend/utils/adt/pgstatfuncs.c' with conflicts. Applied patch to 'src/include/access/tableam.h' cleanly. Applied patch to 'src/include/access/xact.h' cleanly. Applied patch to 'src/include/catalog/pg_proc.dat' cleanly. Applied patch to 'src/include/pgstat.h' with conflicts. Applied patch to 'src/include/utils/pgstat_internal.h' cleanly. Applied patch to 'src/test/recovery/t/029_stats_restart.pl' cleanly. Applied patch to 'src/test/recovery/t/030_stats_cleanup_replica.pl' cleanly. Applied patch to 'src/test/regress/expected/rules.out' cleanly. Applied patch to 'src/test/regress/expected/stats.out' cleanly. Applied patch to 'src/test/regress/sql/stats.sql' cleanly. Applied patch to 'src/test/subscription/t/026_stats.pl' cleanly. Applied patch to 'src/tools/pgindent/typedefs.list' cleanly. U src/backend/utils/activity/pgstat.c U src/backend/utils/adt/pgstatfuncs.c U src/include/pgstat.h diff --cc src/backend/utils/activity/pgstat.c index 3168b825e2,151ba38aa7..0000000000 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@@ -784,10 -769,10 +797,14 @@@ pgstat_report_stat(bool force partial_flush = false; ++<<<<<<< ours + /* flush of variable-numbered stats tracked in pending entries list */ ++======= + /* flush database / relation / function / relfilenode / ... stats */ ++>>>>>>> theirs partial_flush |= pgstat_flush_pending_entries(nowait); - /* flush of fixed-numbered stats */ + /* flush of other stats kinds */ for (PgStat_Kind kind = PGSTAT_KIND_MIN; kind <= PGSTAT_KIND_MAX; kind++) { const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind); @@@ -1353,7 -1345,8 +1372,12 @@@ pgstat_delete_pending_entry(PgStat_Entr } /* ++<<<<<<< ours + * Flush out pending variable-numbered stats. ++======= + * Flush out pending stats for database objects (databases, relations, relfilenodes, + * functions). ++>>>>>>> theirs */ static bool pgstat_flush_pending_entries(bool nowait) diff --cc src/backend/utils/adt/pgstatfuncs.c index e9096a8849,d7cc55c993..0000000000 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@@ -106,33 -106,29 +106,59 @@@ PG_STAT_GET_RELENTRY_INT64(tuples_updat /* pg_stat_get_vacuum_count */ PG_STAT_GET_RELENTRY_INT64(vacuum_count) ++<<<<<<< ours +#define PG_STAT_GET_RELENTRY_FLOAT8(stat) \ +Datum \ +CppConcat(pg_stat_get_,stat)(PG_FUNCTION_ARGS) \ +{ \ + Oid relid = PG_GETARG_OID(0); \ + double result; \ + PgStat_StatTabEntry *tabentry; \ + \ + if ((tabentry = pgstat_fetch_stat_tabentry(relid)) == NULL) \ + result = 0; \ + else \ + result = (double) (tabentry->stat); \ + \ + PG_RETURN_FLOAT8(result); \ +} + +/* pg_stat_get_total_vacuum_time */ +PG_STAT_GET_RELENTRY_FLOAT8(total_vacuum_time) + +/* pg_stat_get_total_autovacuum_time */ +PG_STAT_GET_RELENTRY_FLOAT8(total_autovacuum_time) + +/* pg_stat_get_total_analyze_time */ +PG_STAT_GET_RELENTRY_FLOAT8(total_analyze_time) + +/* pg_stat_get_total_autoanalyze_time */ +PG_STAT_GET_RELENTRY_FLOAT8(total_autoanalyze_time) ++======= + #define PG_STAT_GET_RELFILEENTRY_INT64(stat) \ + Datum \ + CppConcat(pg_stat_get_relfilenode_,stat)(PG_FUNCTION_ARGS) \ + { \ + Oid dboid = PG_GETARG_OID(0); \ + Oid spcOid = PG_GETARG_OID(1); \ + RelFileNumber relfile = PG_GETARG_OID(2); \ + int64 result; \ + PgStat_StatRelFileNodeEntry *relfileentry; \ + \ + if ((relfileentry = pgstat_fetch_stat_relfilenodeentry(dboid, spcOid, relfile)) == NULL) \ + result = 0; \ + else \ + result = (int64) (relfileentry->stat); \ + \ + PG_RETURN_INT64(result); \ + } + + /* pg_stat_get_relfilenode_blocks_written */ + PG_STAT_GET_RELFILEENTRY_INT64(blocks_written) + + /* pg_stat_get_blocks_written */ + PG_STAT_GET_RELENTRY_INT64(blocks_written) ++>>>>>>> theirs #define PG_STAT_GET_RELENTRY_TIMESTAMPTZ(stat) \ Datum \ diff --cc src/include/pgstat.h index 81ec0161c0,ecfbb7cace..0000000000 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@@ -16,11 -16,11 +16,17 @@@ #include "portability/instr_time.h" #include "postmaster/pgarch.h" /* for MAX_XFN_CHARS */ #include "replication/conflict.h" ++<<<<<<< ours +#include "utils/backend_progress.h" /* for backward compatibility */ /* IWYU pragma: export */ +#include "utils/backend_status.h" /* for backward compatibility */ /* IWYU pragma: export */ +#include "utils/pgstat_kind.h" ++======= + #include "storage/relfilelocator.h" + #include "utils/backend_progress.h" /* for backward compatibility */ + #include "utils/backend_status.h" /* for backward compatibility */ ++>>>>>>> theirs #include "utils/relcache.h" -#include "utils/wait_event.h" /* for backward compatibility */ +#include "utils/wait_event.h" /* for backward compatibility */ /* IWYU pragma: export */ /* ---------- @@@ -34,6 -34,62 +40,65 @@@ /* Default directory to store temporary statistics data in */ #define PG_STAT_TMP_DIR "pg_stat_tmp" ++<<<<<<< ours ++======= + /* The types of statistics entries */ + #define PgStat_Kind uint32 + + /* Range of IDs allowed, for built-in and custom kinds */ + #define PGSTAT_KIND_MIN 1 /* Minimum ID allowed */ + #define PGSTAT_KIND_MAX 256 /* Maximum ID allowed */ + + /* use 0 for INVALID, to catch zero-initialized data */ + #define PGSTAT_KIND_INVALID 0 + + /* stats for variable-numbered objects */ + #define PGSTAT_KIND_DATABASE 1 /* database-wide statistics */ + #define PGSTAT_KIND_RELATION 2 /* per-table statistics */ + #define PGSTAT_KIND_RELFILENODE 3 /* per-relfilenode statistics */ + #define PGSTAT_KIND_FUNCTION 4 /* per-function statistics */ + #define PGSTAT_KIND_REPLSLOT 5 /* per-slot statistics */ + #define PGSTAT_KIND_SUBSCRIPTION 6 /* per-subscription statistics */ + + /* stats for fixed-numbered objects */ + #define PGSTAT_KIND_ARCHIVER 7 + #define PGSTAT_KIND_BGWRITER 8 + #define PGSTAT_KIND_CHECKPOINTER 9 + #define PGSTAT_KIND_IO 10 + #define PGSTAT_KIND_SLRU 11 + #define PGSTAT_KIND_WAL 12 + + #define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE + #define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL + #define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1) + + /* Custom stats kinds */ + + /* Range of IDs allowed for custom stats kinds */ + #define PGSTAT_KIND_CUSTOM_MIN 128 + #define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX + #define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1) + + /* + * PgStat_Kind to use for extensions that require an ID, but are still in + * development and have not reserved their own unique kind ID yet. See: + * https://wiki.postgresql.org/wiki/CustomCumulativeStats + */ + #define PGSTAT_KIND_EXPERIMENTAL 128 + + static inline bool + pgstat_is_kind_builtin(PgStat_Kind kind) + { + return kind >= PGSTAT_KIND_BUILTIN_MIN && kind <= PGSTAT_KIND_BUILTIN_MAX; + } + + static inline bool + pgstat_is_kind_custom(PgStat_Kind kind) + { + return kind >= PGSTAT_KIND_CUSTOM_MIN && kind <= PGSTAT_KIND_CUSTOM_MAX; + } + ++>>>>>>> theirs /* Values for track_functions GUC variable --- order is significant! */ typedef enum TrackFunctionsLevel { @@@ -465,13 -464,15 +531,20 @@@ typedef struct PgStat_StatTabEntr PgStat_Counter analyze_count; TimestampTz last_autoanalyze_time; /* autovacuum initiated */ PgStat_Counter autoanalyze_count; + + PgStat_Counter total_vacuum_time; /* times in milliseconds */ + PgStat_Counter total_autovacuum_time; + PgStat_Counter total_analyze_time; + PgStat_Counter total_autoanalyze_time; } PgStat_StatTabEntry; + typedef struct PgStat_StatRelFileNodeEntry + { + PgStat_Counter blocks_fetched; + PgStat_Counter blocks_hit; + PgStat_Counter blocks_written; + } PgStat_StatRelFileNodeEntry; + typedef struct PgStat_WalStats { PgStat_Counter wal_records; @@@ -654,12 -636,15 +727,16 @@@ extern void pgstat_assoc_relation(Relat extern void pgstat_unlink_relation(Relation rel); extern void pgstat_report_vacuum(Oid tableoid, bool shared, - PgStat_Counter livetuples, PgStat_Counter deadtuples); + PgStat_Counter livetuples, PgStat_Counter deadtuples, + TimestampTz starttime); extern void pgstat_report_analyze(Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, - bool resetcounter); + bool resetcounter, TimestampTz starttime); + extern void pgstat_report_relfilenode_blks_written(RelFileLocator locator); + extern void pgstat_report_relfilenode_buffer_read(Relation reln); + extern void pgstat_report_relfilenode_buffer_hit(Relation reln); + /* * If stats are enabled, but pending data hasn't been prepared yet, call * pgstat_assoc_relation() to do so. See its comment for why this is done