@@ -85,7 +85,7 @@ PG_MODULE_MAGIC_EXT(
85
85
#define PGSS_TEXT_FILE PG_STAT_TMP_DIR "/pgss_query_texts.stat"
86
86
87
87
/* Magic number identifying the stats file format */
88
- static const uint32 PGSS_FILE_HEADER = 0x20220408 ;
88
+ static const uint32 PGSS_FILE_HEADER = 0x20250120 ;
89
89
90
90
/* PostgreSQL major version number, changes in which invalidate all entries */
91
91
static const uint32 PGSS_PG_MAJOR_VERSION = PG_VERSION_NUM / 100 ;
@@ -237,7 +237,11 @@ typedef struct pgssEntry
237
237
int encoding ; /* query text encoding */
238
238
TimestampTz stats_since ; /* timestamp of entry allocation */
239
239
TimestampTz minmax_stats_since ; /* timestamp of last min/max values reset */
240
- slock_t mutex ; /* protects the counters only */
240
+ /*
241
+ * protects the counters only. Should be the very last field, as this field
242
+ * isn't copied to PGSS_DUMP_FILE
243
+ */
244
+ slock_t mutex ;
241
245
} pgssEntry ;
242
246
243
247
/*
@@ -628,7 +632,8 @@ pgss_shmem_startup(void)
628
632
pgssEntry * entry ;
629
633
Size query_offset ;
630
634
631
- if (fread (& temp , sizeof (pgssEntry ), 1 , file ) != 1 )
635
+ /* Read whole pgssEntry excluding very last mutex field */
636
+ if (fread (& temp , offsetof(pgssEntry , mutex ), 1 , file ) != 1 )
632
637
goto read_error ;
633
638
634
639
/* Encoding is the only field we can easily sanity-check */
@@ -785,7 +790,8 @@ pgss_shmem_shutdown(int code, Datum arg)
785
790
if (qstr == NULL )
786
791
continue ; /* Ignore any entries with bogus texts */
787
792
788
- if (fwrite (entry , sizeof (pgssEntry ), 1 , file ) != 1 ||
793
+ /* Write whole pgssEntry excluding very last mutex field */
794
+ if (fwrite (entry , offsetof(pgssEntry , mutex ), 1 , file ) != 1 ||
789
795
fwrite (qstr , 1 , len + 1 , file ) != len + 1 )
790
796
{
791
797
/* note: we assume hash_seq_term won't change errno */
0 commit comments