=== Applying patches on top of PostgreSQL commit ID fd2b89854d93d70fe8c9a69d5b8fafd5b9302cfc === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Wed Aug 5 16:05:31 UTC 2026 On branch cf/5958 nothing to commit, working tree clean === using 'git am' to apply patch ./v3-0001-Adding-per-backend-relation-statistics-tracking.patch === Applying: Adding per backend relation statistics tracking Using index info to reconstruct a base tree... M src/backend/utils/activity/pgstat_backend.c M src/backend/utils/activity/pgstat_relation.c M src/include/pgstat.h M src/include/utils/pgstat_internal.h 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/include/utils/pgstat_internal.h CONFLICT (content): Merge conflict in src/include/utils/pgstat_internal.h Auto-merging src/include/pgstat.h CONFLICT (content): Merge conflict in src/include/pgstat.h Auto-merging src/backend/utils/activity/pgstat_relation.c Auto-merging src/backend/utils/activity/pgstat_backend.c CONFLICT (content): Merge conflict in src/backend/utils/activity/pgstat_backend.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 Adding per backend relation statistics tracking 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". === using patch(1) to apply patch ./v3-0001-Adding-per-backend-relation-statistics-tracking.patch === patching file src/backend/utils/activity/pgstat_backend.c Hunk #1 succeeded at 37 with fuzz 2 (offset 1 line). Hunk #2 succeeded at 49 (offset 2 lines). Hunk #3 succeeded at 331 with fuzz 1 (offset 67 lines). Hunk #4 succeeded at 392 with fuzz 1 (offset 71 lines). Hunk #5 succeeded at 414 with fuzz 2 (offset 74 lines). patching file src/backend/utils/activity/pgstat_relation.c Hunk #1 succeeded at 899 (offset 1 line). patching file src/include/pgstat.h Hunk #1 FAILED at 490. Hunk #2 FAILED at 502. Hunk #3 succeeded at 853 (offset 53 lines). 2 out of 3 hunks FAILED -- saving rejects to file src/include/pgstat.h.rej patching file src/include/utils/pgstat_internal.h Hunk #1 FAILED at 616. 1 out of 1 hunk FAILED -- saving rejects to file src/include/utils/pgstat_internal.h.rej patching file src/tools/pgindent/typedefs.list Hunk #1 succeeded at 2335 (offset 108 lines). Unstaged changes after reset: M src/backend/utils/activity/pgstat_backend.c M src/backend/utils/activity/pgstat_relation.c M src/include/pgstat.h M src/tools/pgindent/typedefs.list Removing src/include/pgstat.h.rej Removing src/include/utils/pgstat_internal.h.rej === using 'git apply' to apply patch ./v3-0001-Adding-per-backend-relation-statistics-tracking.patch === Applied patch to 'src/backend/utils/activity/pgstat_backend.c' with conflicts. Applied patch to 'src/backend/utils/activity/pgstat_relation.c' cleanly. Applied patch to 'src/include/pgstat.h' with conflicts. Applied patch to 'src/include/utils/pgstat_internal.h' with conflicts. Applied patch to 'src/tools/pgindent/typedefs.list' cleanly. U src/backend/utils/activity/pgstat_backend.c U src/include/pgstat.h U src/include/utils/pgstat_internal.h diff --cc src/backend/utils/activity/pgstat_backend.c index b736b2ccc6f,0644e999e93..00000000000 --- a/src/backend/utils/activity/pgstat_backend.c +++ b/src/backend/utils/activity/pgstat_backend.c @@@ -37,9 -36,8 +37,9 @@@ * reported within critical sections so we use static memory in order to avoid * memory allocation. */ - static PgStat_BackendPending PendingBackendStats; + PgStat_BackendPending PendingBackendStats; static bool backend_has_iostats = false; +static bool backend_has_lockstats = false; /* * WAL usage counters saved from pgWalUsage at the previous call to @@@ -297,33 -265,36 +302,66 @@@ pgstat_flush_backend_entry_wal(PgStat_E } /* ++<<<<<<< ours + * Flush out locally pending backend lock statistics. Locking is managed + * by the caller. + */ +static void +pgstat_flush_backend_entry_lock(PgStat_EntryRef *entry_ref) +{ + PgStatShared_Backend *shbackendent; + PgStat_PendingLock *bktype_shstats; + + if (!backend_has_lockstats) + return; + + shbackendent = (PgStatShared_Backend *) entry_ref->shared_stats; + bktype_shstats = &shbackendent->stats.lock_stats; + + for (int i = 0; i <= LOCKTAG_LAST_TYPE; i++) + { +#define LOCKSTAT_ACC(fld) \ + (bktype_shstats->stats[i].fld += PendingBackendStats.pending_lock.stats[i].fld) + LOCKSTAT_ACC(waits); + LOCKSTAT_ACC(wait_time); + LOCKSTAT_ACC(fastpath_exceeded); +#undef LOCKSTAT_ACC + } + + MemSet(&PendingBackendStats.pending_lock, 0, sizeof(PgStat_PendingLock)); + backend_has_lockstats = false; ++======= + * Flush out locally pending backend relations's related statistics. Locking is + * managed by the caller. + */ + static void + pgstat_flush_backend_entry_rel(PgStat_EntryRef *entry_ref) + { + PgStatShared_Backend *shbackendent; + + /* + * This function can be called even if nothing at all has happened for + * relations's related statistics. In this case, avoid unnecessarily + * modifying the stats entry. + */ + if (!backend_has_relstats) + return; + + shbackendent = (PgStatShared_Backend *) entry_ref->shared_stats; + + #define BACKENDREL_ACC(stat) \ + (shbackendent->stats.stat += PendingBackendStats.pending_backendrel.stat) + + BACKENDREL_ACC(heap_scan); + #undef BACKENDREL_ACC + + /* + * Clear out the statistics buffer, so it can be re-used. + */ + MemSet(&PendingBackendStats.pending_backendrel, 0, sizeof(PgStat_BackendRelPending)); + + backend_has_relstats = false; ++>>>>>>> theirs } /* @@@ -350,8 -321,8 +388,13 @@@ pgstat_flush_backend(bool nowait, uint3 pgstat_backend_wal_have_pending()) has_pending_data = true; ++<<<<<<< ours + /* Some lock data pending? */ + if ((flags & PGSTAT_BACKEND_FLUSH_LOCK) && backend_has_lockstats) ++======= + /* Some relations related data pending? */ + if ((flags & PGSTAT_BACKEND_FLUSH_REL) && backend_has_relstats) ++>>>>>>> theirs has_pending_data = true; if (!has_pending_data) @@@ -369,8 -340,8 +412,13 @@@ if (flags & PGSTAT_BACKEND_FLUSH_WAL) pgstat_flush_backend_entry_wal(entry_ref); ++<<<<<<< ours + if (flags & PGSTAT_BACKEND_FLUSH_LOCK) + pgstat_flush_backend_entry_lock(entry_ref); ++======= + if (flags & PGSTAT_BACKEND_FLUSH_REL) + pgstat_flush_backend_entry_rel(entry_ref); ++>>>>>>> theirs pgstat_unlock_entry(entry_ref); diff --cc src/include/pgstat.h index 58a44857f13,7d1787d7968..00000000000 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@@ -523,9 -490,14 +523,18 @@@ typedef struct PgStat_Backen TimestampTz stat_reset_timestamp; PgStat_BktypeIO io_stats; PgStat_WalCounters wal_counters; ++<<<<<<< ours + PgStat_PendingLock lock_stats; ++======= + PgStat_Counter heap_scan; ++>>>>>>> theirs } PgStat_Backend; + typedef struct PgStat_BackendRelPending + { + PgStat_Counter heap_scan; + } PgStat_BackendRelPending; + /* --------- * PgStat_BackendPending Non-flushed backend stats. * --------- @@@ -538,10 -510,9 +547,16 @@@ typedef struct PgStat_BackendPendin PgStat_PendingIO pending_io; /* ++<<<<<<< ours + * Backend statistics store the same amount of lock data as + * PGSTAT_KIND_LOCK. + */ + PgStat_PendingLock pending_lock; ++======= + * Backend statistics related to relations. + */ + PgStat_BackendRelPending pending_backendrel; ++>>>>>>> theirs } PgStat_BackendPending; /* diff --cc src/include/utils/pgstat_internal.h index b0a17691966,286249c0f3a..00000000000 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@@ -707,10 -616,10 +707,15 @@@ extern void pgstat_archiver_snapshot_cb /* flags for pgstat_flush_backend() */ #define PGSTAT_BACKEND_FLUSH_IO (1 << 0) /* Flush I/O statistics */ #define PGSTAT_BACKEND_FLUSH_WAL (1 << 1) /* Flush WAL statistics */ ++<<<<<<< ours +#define PGSTAT_BACKEND_FLUSH_LOCK (1 << 2) /* Flush lock statistics */ +#define PGSTAT_BACKEND_FLUSH_ALL (PGSTAT_BACKEND_FLUSH_IO | PGSTAT_BACKEND_FLUSH_WAL | PGSTAT_BACKEND_FLUSH_LOCK) ++======= + #define PGSTAT_BACKEND_FLUSH_REL (1 << 2) /* Flush relations related statistics */ + #define PGSTAT_BACKEND_FLUSH_ALL (PGSTAT_BACKEND_FLUSH_IO | PGSTAT_BACKEND_FLUSH_WAL | PGSTAT_BACKEND_FLUSH_REL) ++>>>>>>> theirs -extern bool pgstat_flush_backend(bool nowait, bits32 flags); +extern bool pgstat_flush_backend(bool nowait, uint32 flags); extern bool pgstat_backend_flush_cb(bool nowait); extern void pgstat_backend_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts);