pg_stat_statements: Add wal_buffers_full
authorMichael Paquier <[email protected]>
Mon, 17 Feb 2025 04:55:17 +0000 (13:55 +0900)
committerMichael Paquier <[email protected]>
Mon, 17 Feb 2025 04:55:17 +0000 (13:55 +0900)
wal_buffers_full tracks the number of times WAL buffers become full,
giving hints to be able to tune the GUC wal_buffers.

Up to now, this information was only available in pg_stat_wal.  With
this field available in WalUsage since eaf502747bac, exposing it in
pg_stat_statements is straight-forward, and it offers more granularity
at query level.

pg_stat_statements does not need a version bump as one has been done in
commit cf54a2c00254 for this development cycle.

Author: Bertrand Drouvot
Reviewed-by: Ilia Evdokimov
Discussion: https://postgr.es/m/[email protected]

contrib/pg_stat_statements/expected/oldextversions.out
contrib/pg_stat_statements/pg_stat_statements--1.11--1.12.sql
contrib/pg_stat_statements/pg_stat_statements.c
doc/src/sgml/pgstatstatements.sgml

index 0c60fc81274b24270454c5c742a7de72ac2a1e37..de679b19711abda28123835028ad591051310e5a 100644 (file)
@@ -385,6 +385,7 @@ AlTER EXTENSION pg_stat_statements UPDATE TO '1.12';
  wal_records                | bigint                   |           |          | 
  wal_fpi                    | bigint                   |           |          | 
  wal_bytes                  | numeric                  |           |          | 
+ wal_buffers_full           | bigint                   |           |          | 
  jit_functions              | bigint                   |           |          | 
  jit_generation_time        | double precision         |           |          | 
  jit_inlining_count         | bigint                   |           |          | 
index 80e6be25445ec4caaa60c33f3988d8ac2eaaf17b..4343d83f0b8cb1cfb84a351b3baaf84a3c15f2b7 100644 (file)
@@ -50,6 +50,7 @@ CREATE FUNCTION pg_stat_statements(IN showtext boolean,
     OUT wal_records int8,
     OUT wal_fpi int8,
     OUT wal_bytes numeric,
+    OUT wal_buffers_full int8,
     OUT jit_functions int8,
     OUT jit_generation_time float8,
     OUT jit_inlining_count int8,
index bebf8134eb02615c94d470262f9cde07c275152f..4a3e855ce90ef15b28bd6c5f37cf3c70311d75eb 100644 (file)
@@ -187,6 +187,7 @@ typedef struct Counters
    int64       wal_records;    /* # of WAL records generated */
    int64       wal_fpi;        /* # of WAL full page images generated */
    uint64      wal_bytes;      /* total amount of WAL generated in bytes */
+   int64       wal_buffers_full;   /* # of times the WAL buffers became full */
    int64       jit_functions;  /* total number of JIT functions emitted */
    double      jit_generation_time;    /* total time to generate jit code */
    int64       jit_inlining_count; /* number of times inlining time has been
@@ -1465,6 +1466,7 @@ pgss_store(const char *query, uint64 queryId,
        entry->counters.wal_records += walusage->wal_records;
        entry->counters.wal_fpi += walusage->wal_fpi;
        entry->counters.wal_bytes += walusage->wal_bytes;
+       entry->counters.wal_buffers_full += walusage->wal_buffers_full;
        if (jitusage)
        {
            entry->counters.jit_functions += jitusage->created_functions;
@@ -1557,8 +1559,8 @@ pg_stat_statements_reset(PG_FUNCTION_ARGS)
 #define PG_STAT_STATEMENTS_COLS_V1_9   33
 #define PG_STAT_STATEMENTS_COLS_V1_10  43
 #define PG_STAT_STATEMENTS_COLS_V1_11  49
-#define PG_STAT_STATEMENTS_COLS_V1_12  51
-#define PG_STAT_STATEMENTS_COLS            51  /* maximum of above */
+#define PG_STAT_STATEMENTS_COLS_V1_12  52
+#define PG_STAT_STATEMENTS_COLS            52  /* maximum of above */
 
 /*
  * Retrieve statement statistics.
@@ -1955,6 +1957,10 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
                                            Int32GetDatum(-1));
            values[i++] = wal_bytes;
        }
+       if (api_version >= PGSS_V1_12)
+       {
+           values[i++] = Int64GetDatumFast(tmp.wal_buffers_full);
+       }
        if (api_version >= PGSS_V1_10)
        {
            values[i++] = Int64GetDatumFast(tmp.jit_functions);
index 501b468e9af277f66537e7d2b49f880ca50e1883..e2ac1c2d50107ea25a5449b5a8ac3d15f5964cab 100644 (file)
       </para></entry>
      </row>
 
+     <row>
+      <entry role="catalog_table_entry"><para role="column_definition">
+       <structfield>wal_buffers_full</structfield> <type>bigint</type>
+      </para>
+      <para>
+       Number of times the WAL buffers became full
+      </para></entry>
+     </row>
+
      <row>
       <entry role="catalog_table_entry"><para role="column_definition">
        <structfield>jit_functions</structfield> <type>bigint</type>