pg_stat_statements_file.patch
application/octet-stream
Filename: pg_stat_statements_file.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| contrib/pg_stat_statements/pg_stat_statements.c | 20 | 2 |
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 8347c8e..1ebda8b 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -511,6 +511,13 @@ pgss_shmem_startup(void)
pfree(buffer);
FreeFile(file);
+
+ /*
+ * Remove the file so it's not included in backups/replication
+ * slaves, etc. A new file will be written on next shutdown.
+ */
+ unlink(PGSS_DUMP_FILE);
+
return;
error:
@@ -552,7 +559,7 @@ pgss_shmem_shutdown(int code, Datum arg)
if (!pgss_save)
return;
- file = AllocateFile(PGSS_DUMP_FILE, PG_BINARY_W);
+ file = AllocateFile(PGSS_DUMP_FILE ".tmp", PG_BINARY_W);
if (file == NULL)
goto error;
@@ -578,6 +585,17 @@ pgss_shmem_shutdown(int code, Datum arg)
goto error;
}
+ /*
+ * Rename file into place, so we atomically replace the old one.
+ */
+ if (rename(PGSS_DUMP_FILE ".tmp", PGSS_DUMP_FILE) != 0)
+ {
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not rename pg_stat_statement file \"%s.tmp\": %m",
+ PGSS_DUMP_FILE)));
+ }
+
return;
error:
@@ -587,7 +605,7 @@ error:
PGSS_DUMP_FILE)));
if (file)
FreeFile(file);
- unlink(PGSS_DUMP_FILE);
+ unlink(PGSS_DUMP_FILE ".tmp");
}
/*