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

Commit 3e8554a

Browse files
committed
Make pg_basebackup skip temporary statistics files.
The temporary statistics files don't need to be included in the backup because they are always reset at the beginning of the archive recovery. This patch changes pg_basebackup so that it skips all files located in $PGDATA/pg_stat_tmp or the directory specified by stats_temp_directory parameter.
1 parent 47aaeba commit 3e8554a

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "parser/analyze.h"
6969
#include "parser/parsetree.h"
7070
#include "parser/scanner.h"
71+
#include "pgstat.h"
7172
#include "storage/fd.h"
7273
#include "storage/ipc.h"
7374
#include "storage/spin.h"
@@ -89,7 +90,7 @@ PG_MODULE_MAGIC;
8990
* race conditions. Besides, we only expect modest, infrequent I/O for query
9091
* strings, so placing the file on a faster filesystem is not compelling.
9192
*/
92-
#define PGSS_TEXT_FILE "pg_stat_tmp/pgss_query_texts.stat"
93+
#define PGSS_TEXT_FILE PG_STAT_TMP_DIR "/pgss_query_texts.stat"
9394

9495
/* Magic number identifying the stats file format */
9596
static const uint32 PGSS_FILE_HEADER = 0x20140125;

src/backend/replication/basebackup.c

+30-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "libpq/pqformat.h"
2626
#include "miscadmin.h"
2727
#include "nodes/pg_list.h"
28+
#include "pgstat.h"
2829
#include "replication/basebackup.h"
2930
#include "replication/walsender.h"
3031
#include "replication/walsender_private.h"
@@ -63,6 +64,9 @@ static int compareWalFileNames(const void *a, const void *b);
6364
/* Was the backup currently in-progress initiated in recovery mode? */
6465
static bool backup_started_in_recovery = false;
6566

67+
/* Relative path of temporary statistics directory */
68+
static char *statrelpath = NULL;
69+
6670
/*
6771
* Size of each block sent into the tar stream for larger files.
6872
*/
@@ -111,6 +115,18 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
111115
&labelfile);
112116
SendXlogRecPtrResult(startptr, starttli);
113117

118+
/*
119+
* Calculate the relative path of temporary statistics directory
120+
* in order to skip the files which are located in that directory later.
121+
*/
122+
if (is_absolute_path(pgstat_stat_directory) &&
123+
strncmp(pgstat_stat_directory, DataDir, datadirpathlen) == 0)
124+
statrelpath = psprintf("./%s", pgstat_stat_directory + datadirpathlen + 1);
125+
else if (strncmp(pgstat_stat_directory, "./", 2) != 0)
126+
statrelpath = psprintf("./%s", pgstat_stat_directory);
127+
else
128+
statrelpath = pgstat_stat_directory;
129+
114130
PG_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum) 0);
115131
{
116132
List *tablespaces = NIL;
@@ -838,7 +854,6 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
838854
sizeof(PG_AUTOCONF_FILENAME) + 4) == 0)
839855
continue;
840856

841-
842857
/*
843858
* If there's a backup_label file, it belongs to a backup started by
844859
* the user with pg_start_backup(). It is *not* correct for this
@@ -891,6 +906,20 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
891906
continue;
892907
}
893908

909+
/*
910+
* Skip temporary statistics files. PG_STAT_TMP_DIR must be skipped
911+
* even when stats_temp_directory is set because PGSS_TEXT_FILE is
912+
* always created there.
913+
*/
914+
if ((statrelpath != NULL && strcmp(pathbuf, statrelpath) == 0) ||
915+
strncmp(de->d_name, PG_STAT_TMP_DIR, strlen(PG_STAT_TMP_DIR)) == 0)
916+
{
917+
if (!sizeonly)
918+
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
919+
size += 512;
920+
continue;
921+
}
922+
894923
/*
895924
* We can skip pg_xlog, the WAL segments need to be fetched from the
896925
* WAL archive anyway. But include it as an empty directory anyway, so

src/backend/utils/misc/guc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3174,7 +3174,7 @@ static struct config_string ConfigureNamesString[] =
31743174
GUC_SUPERUSER_ONLY
31753175
},
31763176
&pgstat_temp_directory,
3177-
"pg_stat_tmp",
3177+
PG_STAT_TMP_DIR,
31783178
check_canonical_path, assign_pgstat_temp_directory, NULL
31793179
},
31803180

src/include/pgstat.h

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "utils/relcache.h"
2121

2222

23+
/* Default directory to store temporary statistics data in */
24+
#define PG_STAT_TMP_DIR "pg_stat_tmp"
25+
2326
/* Values for track_functions GUC variable --- order is significant! */
2427
typedef enum TrackFunctionsLevel
2528
{

0 commit comments

Comments
 (0)