=== Applying patches on top of PostgreSQL commit ID 4464fddf7b50abe3dbb462f76fd925e10eedad1c === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Fri Jun 20 15:43:18 UTC 2025 On branch cf/5007 nothing to commit, working tree clean === using 'git am' to apply patch ./v6-0001-Clear-padding-in-PgStat_HashKey-keys.patch === Applying: Clear padding in PgStat_HashKey keys Using index info to reconstruct a base tree... M src/backend/utils/activity/pgstat.c M src/backend/utils/activity/pgstat_shmem.c Falling back to patching base and 3-way merge... Auto-merging src/backend/utils/activity/pgstat_shmem.c Auto-merging src/backend/utils/activity/pgstat.c No changes -- Patch already applied. === using 'git am' to apply patch ./v6-0002-Provide-relfilenode-statistics.patch === Applying: Provide relfilenode statistics Using index info to reconstruct a base tree... M src/backend/access/rmgrdesc/xactdesc.c M src/backend/catalog/storage.c M src/backend/catalog/system_functions.sql M src/backend/catalog/system_views.sql M src/backend/postmaster/checkpointer.c M src/backend/storage/buffer/bufmgr.c M src/backend/storage/smgr/md.c M src/backend/utils/activity/pgstat.c M src/backend/utils/activity/pgstat_database.c M src/backend/utils/activity/pgstat_function.c M src/backend/utils/activity/pgstat_relation.c M src/backend/utils/activity/pgstat_replslot.c M src/backend/utils/activity/pgstat_shmem.c M src/backend/utils/activity/pgstat_subscription.c M src/backend/utils/activity/pgstat_xact.c M src/backend/utils/adt/pgstatfuncs.c M src/include/access/tableam.h M src/include/access/xact.h M src/include/catalog/pg_proc.dat M src/include/pgstat.h M src/include/utils/pgstat_internal.h M src/test/recovery/t/029_stats_restart.pl M src/test/recovery/t/030_stats_cleanup_replica.pl M src/test/regress/expected/rules.out M src/test/regress/expected/stats.out M src/test/regress/sql/stats.sql M src/test/subscription/t/026_stats.pl M src/tools/pgindent/typedefs.list Falling back to patching base and 3-way merge... Auto-merging src/tools/pgindent/typedefs.list Auto-merging src/test/subscription/t/026_stats.pl Auto-merging src/test/regress/sql/stats.sql Auto-merging src/test/regress/expected/stats.out Auto-merging src/test/regress/expected/rules.out Auto-merging src/test/recovery/t/030_stats_cleanup_replica.pl Auto-merging src/test/recovery/t/029_stats_restart.pl CONFLICT (content): Merge conflict in src/test/recovery/t/029_stats_restart.pl Auto-merging src/include/utils/pgstat_internal.h Auto-merging src/include/pgstat.h CONFLICT (content): Merge conflict in src/include/pgstat.h Auto-merging src/include/catalog/pg_proc.dat Auto-merging src/include/access/xact.h Auto-merging src/include/access/tableam.h Auto-merging src/backend/utils/adt/pgstatfuncs.c CONFLICT (content): Merge conflict in src/backend/utils/adt/pgstatfuncs.c Auto-merging src/backend/utils/activity/pgstat_xact.c CONFLICT (content): Merge conflict in src/backend/utils/activity/pgstat_xact.c Auto-merging src/backend/utils/activity/pgstat_subscription.c Auto-merging src/backend/utils/activity/pgstat_shmem.c CONFLICT (content): Merge conflict in src/backend/utils/activity/pgstat_shmem.c Auto-merging src/backend/utils/activity/pgstat_replslot.c Auto-merging src/backend/utils/activity/pgstat_relation.c Auto-merging src/backend/utils/activity/pgstat_function.c Auto-merging src/backend/utils/activity/pgstat_database.c CONFLICT (content): Merge conflict in src/backend/utils/activity/pgstat_database.c Auto-merging src/backend/utils/activity/pgstat.c CONFLICT (content): Merge conflict in src/backend/utils/activity/pgstat.c Auto-merging src/backend/storage/smgr/md.c Auto-merging src/backend/storage/buffer/bufmgr.c Auto-merging src/backend/postmaster/checkpointer.c Auto-merging src/backend/catalog/system_views.sql Auto-merging src/backend/catalog/system_functions.sql Auto-merging src/backend/catalog/storage.c Auto-merging src/backend/access/rmgrdesc/xactdesc.c CONFLICT (content): Merge conflict in src/backend/access/rmgrdesc/xactdesc.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Provide relfilenode statistics When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/access/rmgrdesc/xactdesc.c M src/backend/catalog/storage.c M src/backend/catalog/system_functions.sql M src/backend/catalog/system_views.sql M src/backend/postmaster/checkpointer.c M src/backend/storage/buffer/bufmgr.c M src/backend/storage/smgr/md.c M src/backend/utils/activity/pgstat.c M src/backend/utils/activity/pgstat_database.c M src/backend/utils/activity/pgstat_function.c M src/backend/utils/activity/pgstat_relation.c M src/backend/utils/activity/pgstat_replslot.c M src/backend/utils/activity/pgstat_shmem.c M src/backend/utils/activity/pgstat_subscription.c M src/backend/utils/activity/pgstat_xact.c M src/backend/utils/adt/pgstatfuncs.c M src/include/access/tableam.h M src/include/access/xact.h M src/include/catalog/pg_proc.dat M src/include/pgstat.h M src/include/utils/pgstat_internal.h M src/test/recovery/t/029_stats_restart.pl M src/test/recovery/t/030_stats_cleanup_replica.pl M src/test/regress/expected/rules.out M src/test/regress/expected/stats.out M src/test/regress/sql/stats.sql M src/test/subscription/t/026_stats.pl M src/tools/pgindent/typedefs.list === using patch(1) to apply patch ./v6-0002-Provide-relfilenode-statistics.patch === patching file src/backend/access/rmgrdesc/xactdesc.c Hunk #1 FAILED at 322. 1 out of 1 hunk FAILED -- saving rejects to file src/backend/access/rmgrdesc/xactdesc.c.rej patching file src/backend/catalog/storage.c Hunk #1 succeeded at 34 (offset 1 line). Hunk #2 succeeded at 154 (offset 1 line). Hunk #3 succeeded at 230 (offset 1 line). Hunk #4 succeeded at 258 (offset 1 line). Hunk #5 succeeded at 275 (offset 1 line). patching file src/backend/catalog/system_functions.sql Hunk #1 succeeded at 697 (offset -21 lines). patching file src/backend/catalog/system_views.sql Hunk #1 succeeded at 763 (offset 17 lines). Hunk #2 succeeded at 772 (offset 17 lines). Hunk #3 succeeded at 789 (offset 17 lines). patching file src/backend/postmaster/checkpointer.c Hunk #1 succeeded at 549 (offset 19 lines). patching file src/backend/storage/buffer/bufmgr.c Hunk #1 succeeded at 1163 (offset 4 lines). Hunk #2 succeeded at 4401 (offset 506 lines). patching file src/backend/storage/smgr/md.c Hunk #1 succeeded at 39 (offset 1 line). Hunk #2 succeeded at 1589 (offset 120 lines). Hunk #3 succeeded at 1609 (offset 120 lines). patching file src/backend/utils/activity/pgstat.c Hunk #1 succeeded at 310 (offset 3 lines). Hunk #2 FAILED at 769. Hunk #3 succeeded at 877 (offset 19 lines). Hunk #4 succeeded at 886 (offset 19 lines). Hunk #5 succeeded at 957 (offset 19 lines). Hunk #6 succeeded at 976 (offset 19 lines). Hunk #7 succeeded at 1002 (offset 19 lines). Hunk #8 succeeded at 1071 (offset 19 lines). Hunk #9 succeeded at 1292 (offset 19 lines). Hunk #10 succeeded at 1308 (offset 19 lines). Hunk #11 succeeded at 1331 (offset 19 lines). Hunk #12 FAILED at 1345. Hunk #13 FAILED at 1665. Hunk #14 FAILED at 1903. Hunk #15 FAILED at 1976. Hunk #16 FAILED at 1989. 6 out of 16 hunks FAILED -- saving rejects to file src/backend/utils/activity/pgstat.c.rej patching file src/backend/utils/activity/pgstat_database.c Hunk #3 FAILED at 150. Hunk #4 succeeded at 278 (offset 36 lines). Hunk #5 succeeded at 394 (offset 53 lines). Hunk #6 succeeded at 410 (offset 53 lines). 1 out of 6 hunks FAILED -- saving rejects to file src/backend/utils/activity/pgstat_database.c.rej patching file src/backend/utils/activity/pgstat_function.c patching file src/backend/utils/activity/pgstat_relation.c Hunk #5 succeeded at 229 (offset 3 lines). Hunk #6 succeeded at 331 (offset 12 lines). Hunk #7 succeeded at 475 (offset 15 lines). Hunk #8 succeeded at 498 (offset 15 lines). Hunk #9 succeeded at 521 (offset 15 lines). Hunk #10 succeeded at 917 (offset 24 lines). Hunk #11 succeeded at 970 (offset 24 lines). Hunk #12 succeeded at 978 (offset 24 lines). patching file src/backend/utils/activity/pgstat_replslot.c patching file src/backend/utils/activity/pgstat_shmem.c Hunk #1 succeeded at 442 (offset 13 lines). Hunk #2 succeeded at 456 (offset 13 lines). Hunk #3 succeeded at 693 (offset 40 lines). Hunk #4 FAILED at 828. Hunk #5 succeeded at 961 (offset 47 lines). Hunk #6 succeeded at 973 (offset 47 lines). Hunk #7 succeeded at 1073 (offset 76 lines). 1 out of 7 hunks FAILED -- saving rejects to file src/backend/utils/activity/pgstat_shmem.c.rej patching file src/backend/utils/activity/pgstat_subscription.c patching file src/backend/utils/activity/pgstat_xact.c Hunk #9 FAILED at 396. 1 out of 10 hunks FAILED -- saving rejects to file src/backend/utils/activity/pgstat_xact.c.rej patching file src/backend/utils/adt/pgstatfuncs.c Hunk #1 succeeded at 134 with fuzz 2 (offset 28 lines). Hunk #2 succeeded at 1946 (offset 158 lines). Hunk #3 succeeded at 1956 (offset 158 lines). Hunk #4 succeeded at 2049 (offset 193 lines). Hunk #5 succeeded at 2278 (offset 195 lines). patching file src/include/access/tableam.h Hunk #2 succeeded at 1586 (offset -49 lines). patching file src/include/access/xact.h patching file src/include/catalog/pg_proc.dat Hunk #1 succeeded at 5540 (offset 71 lines). Hunk #2 succeeded at 5587 (offset 71 lines). Hunk #3 succeeded at 5693 (offset 87 lines). patching file src/include/pgstat.h Hunk #1 FAILED at 16. Hunk #2 FAILED at 46. Hunk #3 succeeded at 439 (offset -13 lines). Hunk #4 FAILED at 464. Hunk #5 succeeded at 526 (offset 12 lines). Hunk #6 succeeded at 535 (offset 12 lines). Hunk #7 succeeded at 647 with fuzz 2 (offset 15 lines). Hunk #8 succeeded at 729 (offset 34 lines). 3 out of 8 hunks FAILED -- saving rejects to file src/include/pgstat.h.rej patching file src/include/utils/pgstat_internal.h Hunk #2 succeeded at 440 (offset 29 lines). Hunk #3 succeeded at 589 (offset 34 lines). Hunk #4 succeeded at 609 (offset 34 lines). Hunk #5 succeeded at 705 (offset 48 lines). Hunk #6 FAILED at 678. Hunk #7 succeeded at 783 (offset 48 lines). 1 out of 7 hunks FAILED -- saving rejects to file src/include/utils/pgstat_internal.h.rej patching file src/test/recovery/t/029_stats_restart.pl Hunk #1 FAILED at 40. Hunk #2 succeeded at 79 (offset 15 lines). Hunk #3 succeeded at 96 (offset 15 lines). Hunk #4 succeeded at 110 (offset 15 lines). Hunk #5 succeeded at 129 (offset 15 lines). Hunk #6 succeeded at 145 (offset 15 lines). Hunk #7 succeeded at 307 (offset 15 lines). 1 out of 7 hunks FAILED -- saving rejects to file src/test/recovery/t/029_stats_restart.pl.rej patching file src/test/recovery/t/030_stats_cleanup_replica.pl patching file src/test/regress/expected/rules.out Hunk #1 succeeded at 2378 (offset 36 lines). Hunk #2 succeeded at 2390 (offset 36 lines). Hunk #3 succeeded at 2402 (offset 36 lines). Hunk #4 succeeded at 2423 (offset 36 lines). Hunk #5 succeeded at 2453 (offset 36 lines). patching file src/test/regress/expected/stats.out Hunk #1 succeeded at 1212 (offset 101 lines). Hunk #2 succeeded at 1245 (offset 101 lines). Hunk #3 succeeded at 1275 (offset 101 lines). Hunk #4 succeeded at 1297 (offset 101 lines). Hunk #5 succeeded at 1305 (offset 101 lines). Hunk #6 succeeded at 1313 (offset 101 lines). Hunk #7 succeeded at 1321 (offset 101 lines). Hunk #8 succeeded at 1329 (offset 101 lines). Hunk #9 succeeded at 1675 (offset 162 lines). patching file src/test/regress/sql/stats.sql Hunk #1 succeeded at 552 (offset 13 lines). Hunk #2 succeeded at 565 (offset 13 lines). Hunk #3 succeeded at 803 with fuzz 1 (offset 44 lines). patching file src/test/subscription/t/026_stats.pl patching file src/tools/pgindent/typedefs.list Hunk #1 succeeded at 2212 with fuzz 2 (offset 85 lines). Unstaged changes after reset: M src/backend/catalog/storage.c M src/backend/catalog/system_functions.sql M src/backend/catalog/system_views.sql M src/backend/postmaster/checkpointer.c M src/backend/storage/buffer/bufmgr.c M src/backend/storage/smgr/md.c M src/backend/utils/activity/pgstat.c M src/backend/utils/activity/pgstat_database.c M src/backend/utils/activity/pgstat_function.c M src/backend/utils/activity/pgstat_relation.c M src/backend/utils/activity/pgstat_replslot.c M src/backend/utils/activity/pgstat_shmem.c M src/backend/utils/activity/pgstat_subscription.c M src/backend/utils/activity/pgstat_xact.c M src/backend/utils/adt/pgstatfuncs.c M src/include/access/tableam.h M src/include/access/xact.h M src/include/catalog/pg_proc.dat M src/include/pgstat.h M src/include/utils/pgstat_internal.h M src/test/recovery/t/029_stats_restart.pl M src/test/recovery/t/030_stats_cleanup_replica.pl M src/test/regress/expected/rules.out M src/test/regress/expected/stats.out M src/test/regress/sql/stats.sql M src/test/subscription/t/026_stats.pl M src/tools/pgindent/typedefs.list Removing src/backend/access/rmgrdesc/xactdesc.c.rej Removing src/backend/utils/activity/pgstat.c.rej Removing src/backend/utils/activity/pgstat_database.c.rej Removing src/backend/utils/activity/pgstat_shmem.c.rej Removing src/backend/utils/activity/pgstat_xact.c.rej Removing src/include/pgstat.h.rej Removing src/include/utils/pgstat_internal.h.rej Removing src/test/recovery/t/029_stats_restart.pl.rej === using 'git apply' to apply patch ./v6-0002-Provide-relfilenode-statistics.patch === Applied patch to 'src/backend/access/rmgrdesc/xactdesc.c' with conflicts. 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' with conflicts. 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' with conflicts. Applied patch to 'src/backend/utils/activity/pgstat_subscription.c' cleanly. Applied patch to 'src/backend/utils/activity/pgstat_xact.c' with conflicts. 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' with conflicts. 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/access/rmgrdesc/xactdesc.c U src/backend/utils/activity/pgstat.c U src/backend/utils/activity/pgstat_database.c U src/backend/utils/activity/pgstat_shmem.c U src/backend/utils/activity/pgstat_xact.c U src/backend/utils/adt/pgstatfuncs.c U src/include/pgstat.h U src/test/recovery/t/029_stats_restart.pl diff --cc src/backend/access/rmgrdesc/xactdesc.c index 305598e2865,5a15cdd4609..00000000000 --- a/src/backend/access/rmgrdesc/xactdesc.c +++ b/src/backend/access/rmgrdesc/xactdesc.c @@@ -322,10 -322,11 +322,18 @@@ xact_desc_stats(StringInfo buf, const c uint64 objid = ((uint64) dropped_stats[i].objid_hi) << 32 | dropped_stats[i].objid_lo; ++<<<<<<< ours + appendStringInfo(buf, " %d/%u/%" PRIu64, + dropped_stats[i].kind, + dropped_stats[i].dboid, + objid); ++======= + appendStringInfo(buf, " %d/%u/%llu/%u", + dropped_stats[i].kind, + dropped_stats[i].dboid, + (unsigned long long) objid, + dropped_stats[i].relfile); ++>>>>>>> theirs } } } diff --cc src/backend/utils/activity/pgstat.c index 8b57845e870,151ba38aa7d..00000000000 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@@ -780,10 -769,10 +793,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); @@@ -1349,7 -1345,8 +1368,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) @@@ -1676,9 -1665,10 +1700,16 @@@ pgstat_write_statsfile(void */ if (!pgstat_is_kind_valid(ps->key.kind)) { ++<<<<<<< ours + elog(WARNING, "found unknown stats entry %u/%u/%" PRIu64, + ps->key.kind, ps->key.dboid, + ps->key.objid); ++======= + elog(WARNING, "found unknown stats entry %u/%u/%llu/%u", + ps->key.kind, ps->key.dboid, + (unsigned long long) ps->key.objid, + ps->key.relfile); ++>>>>>>> theirs continue; } @@@ -1900,17 -1904,9 +1931,23 @@@ pgstat_read_statsfile(void if (!pgstat_is_kind_valid(key.kind)) { ++<<<<<<< ours + elog(WARNING, "invalid stats kind for entry %u/%u/%" PRIu64 " of type %c", + key.kind, key.dboid, + key.objid, t); + goto error; + } + + if (!pgstat_get_kind_info(key.kind)) + { + elog(WARNING, "could not find information of kind for entry %u/%u/%" PRIu64 " of type %c", + key.kind, key.dboid, + key.objid, t); ++======= + elog(WARNING, "invalid stats kind for entry %u/%u/%llu/%u of type %c", + key.kind, key.dboid, + (unsigned long long) key.objid, key.relfile, t); ++>>>>>>> theirs goto error; } } @@@ -1981,9 -1977,9 +2018,15 @@@ if (found) { dshash_release_lock(pgStatLocal.shared_hash, p); ++<<<<<<< ours + elog(WARNING, "found duplicate stats entry %u/%u/%" PRIu64 " of type %c", + key.kind, key.dboid, + key.objid, t); ++======= + elog(WARNING, "found duplicate stats entry %u/%u/%llu/%u of type %c", + key.kind, key.dboid, + (unsigned long long) key.objid, key.relfile, t); ++>>>>>>> theirs goto error; } @@@ -1994,9 -1990,9 +2037,15 @@@ pgstat_get_entry_data(key.kind, header), pgstat_get_entry_len(key.kind))) { ++<<<<<<< ours + elog(WARNING, "could not read data for entry %u/%u/%" PRIu64 " of type %c", + key.kind, key.dboid, + key.objid, t); ++======= + elog(WARNING, "could not read data for entry %u/%u/%llu/%u of type %c", + key.kind, key.dboid, + (unsigned long long) key.objid, key.relfile, t); ++>>>>>>> theirs goto error; } diff --cc src/backend/utils/activity/pgstat_database.c index b31f20d41bc,cf77f2dbdb2..00000000000 --- a/src/backend/utils/activity/pgstat_database.c +++ b/src/backend/utils/activity/pgstat_database.c @@@ -173,29 -147,10 +173,34 @@@ pgstat_report_checksum_failures_in_db(O /* * Update the shared stats directly - checksum failures should never be - * common enough for that to be a problem. + * common enough for that to be a problem. Note that we pass create=false + * here, as we want to be sure to not require memory allocations, so this + * can be called in critical sections. + */ + entry_ref = pgstat_get_entry_ref(PGSTAT_KIND_DATABASE, dboid, InvalidOid, + false, NULL); + + /* + * Should always have been created by + * pgstat_prepare_report_checksum_failure(). + * + * When not using assertions, we don't want to crash should something have + * gone wrong, so just return. */ ++<<<<<<< ours + Assert(entry_ref); + if (!entry_ref) + { + elog(WARNING, "could not report %d conflicts for DB %u", + failurecount, dboid); + return; + } + + (void) pgstat_lock_entry(entry_ref, false); ++======= + entry_ref = + pgstat_get_entry_ref_locked(PGSTAT_KIND_DATABASE, dboid, InvalidOid, InvalidOid, false); ++>>>>>>> theirs sharedent = (PgStatShared_Database *) entry_ref->shared_stats; sharedent->stats.checksum_failures += failurecount; diff --cc src/backend/utils/activity/pgstat_shmem.c index 53e7d534270,82f955a0b26..00000000000 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@@ -874,10 -828,11 +875,18 @@@ pgstat_drop_entry_internal(PgStatShared */ if (shent->dropped) elog(ERROR, ++<<<<<<< ours + "trying to drop stats entry already dropped: kind=%s dboid=%u objid=%" PRIu64 " refcount=%u", + pgstat_get_kind_info(shent->key.kind)->name, + shent->key.dboid, + shent->key.objid, ++======= + "trying to drop stats entry already dropped: kind=%s dboid=%u objid=%llu relfile=%u refcount=%u", + pgstat_get_kind_info(shent->key.kind)->name, + shent->key.dboid, + (unsigned long long) shent->key.objid, + shent->key.relfile, ++>>>>>>> theirs pg_atomic_read_u32(&shent->refcount)); shent->dropped = true; diff --cc src/backend/utils/activity/pgstat_xact.c index bc9864bd8d9,4c663b7d625..00000000000 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@@ -358,19 -396,19 +396,25 @@@ create_drop_transactional_internal(PgSt * dropped. */ void - pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid) + pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid, RelFileNumber relfile) { - if (pgstat_get_entry_ref(kind, dboid, objid, false, NULL)) + if (pgstat_get_entry_ref(kind, dboid, objid, relfile, false, NULL)) { ereport(WARNING, ++<<<<<<< ours + errmsg("resetting existing statistics for kind %s, db=%u, oid=%" PRIu64, + (pgstat_get_kind_info(kind))->name, dboid, + objid)); ++======= + errmsg("resetting existing statistics for kind %s, db=%u, oid=%llu, relfile=%u", + (pgstat_get_kind_info(kind))->name, dboid, + (unsigned long long) objid, relfile)); ++>>>>>>> theirs - pgstat_reset(kind, dboid, objid); + pgstat_reset(kind, dboid, objid, relfile); } - create_drop_transactional_internal(kind, dboid, objid, /* create */ true); + create_drop_transactional_internal(kind, dboid, objid, relfile, /* create */ true); } /* diff --cc src/backend/utils/adt/pgstatfuncs.c index 1c12ddbae49,d7cc55c9936..00000000000 --- 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 378f2f2c2ba,ecfbb7cace0..00000000000 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@@ -15,11 -16,11 +15,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 */ /* ---------- @@@ -33,6 -34,62 +39,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 { @@@ -448,22 -464,16 +514,33 @@@ 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; ++<<<<<<< ours +/* ------ + * PgStat_WalCounters WAL activity data gathered from WalUsage + * + * This stores all the counters and data gathered from WalUsage for WAL + * activity statistics, separated into its own structure so as this can be + * shared across multiple Stats structures. + * ------ + */ +typedef struct PgStat_WalCounters ++======= + typedef struct PgStat_StatRelFileNodeEntry + { + PgStat_Counter blocks_fetched; + PgStat_Counter blocks_hit; + PgStat_Counter blocks_written; + } PgStat_StatRelFileNodeEntry; + + typedef struct PgStat_WalStats ++>>>>>>> theirs { PgStat_Counter wal_records; PgStat_Counter wal_fpi; @@@ -659,12 -636,15 +736,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 diff --cc src/test/recovery/t/029_stats_restart.pl index 021e2bf361f,4c83a0c1679..00000000000 --- a/src/test/recovery/t/029_stats_restart.pl +++ b/src/test/recovery/t/029_stats_restart.pl @@@ -54,11 -39,11 +54,17 @@@ my $tableoid = $node->safe_psql($db_und trigger_funcrel_stat(); # verify stats objects exist ++<<<<<<< ours +$sect = "initial"; +is(have_stats('database', $dboid, 0), 't', "$sect: db stats do exist"); +is(have_stats('function', $dboid, $funcoid), ++======= + my $sect = "initial"; + is(have_stats('database', $dboid, 0, 0), 't', "$sect: db stats do exist"); + is(have_stats('function', $dboid, $funcoid, 0), ++>>>>>>> theirs 't', "$sect: function stats do exist"); - is(have_stats('relation', $dboid, $tableoid), + is(have_stats('relation', $dboid, $tableoid, 0), 't', "$sect: relation stats do exist"); # regular shutdown