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

Commit a8813c8

Browse files
author
Commitfest Bot
committed
[CF 5512] v2 - pg_stat_statements: improve loading and saving routines for the dump file.
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5512 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/181d7759a2ed7d819add4e0086e7a7f9@postgrespro.ru Author(s): Mikhail Litsarev
2 parents 67be093 + 508decc commit a8813c8

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)