Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 508decc

Browse files
Mikhail LitsarevCommitfest Bot
Mikhail Litsarev
authored and
Commitfest Bot
committed
pg_stat_statements: improve loading and saving routines for the dump file.
Exclude reading/writing pgssEntry mutex from/into the dump file. Update the magic number identifying the stats file format.
1 parent 67be093 commit 508decc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ PG_MODULE_MAGIC_EXT(
8585
#define PGSS_TEXT_FILE PG_STAT_TMP_DIR "/pgss_query_texts.stat"
8686

8787
/* Magic number identifying the stats file format */
88-
static const uint32 PGSS_FILE_HEADER = 0x20220408;
88+
static const uint32 PGSS_FILE_HEADER = 0x20250120;
8989

9090
/* PostgreSQL major version number, changes in which invalidate all entries */
9191
static const uint32 PGSS_PG_MAJOR_VERSION = PG_VERSION_NUM / 100;
@@ -237,7 +237,11 @@ typedef struct pgssEntry
237237
int encoding; /* query text encoding */
238238
TimestampTz stats_since; /* timestamp of entry allocation */
239239
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;
241245
} pgssEntry;
242246

243247
/*
@@ -628,7 +632,8 @@ pgss_shmem_startup(void)
628632
pgssEntry *entry;
629633
Size query_offset;
630634

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)
632637
goto read_error;
633638

634639
/* Encoding is the only field we can easily sanity-check */
@@ -785,7 +790,8 @@ pgss_shmem_shutdown(int code, Datum arg)
785790
if (qstr == NULL)
786791
continue; /* Ignore any entries with bogus texts */
787792

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 ||
789795
fwrite(qstr, 1, len + 1, file) != len + 1)
790796
{
791797
/* note: we assume hash_seq_term won't change errno */

0 commit comments

Comments
 (0)