|
25 | 25 | #include "libpq/pqformat.h"
|
26 | 26 | #include "miscadmin.h"
|
27 | 27 | #include "nodes/pg_list.h"
|
| 28 | +#include "pgstat.h" |
28 | 29 | #include "replication/basebackup.h"
|
29 | 30 | #include "replication/walsender.h"
|
30 | 31 | #include "replication/walsender_private.h"
|
@@ -63,6 +64,9 @@ static int compareWalFileNames(const void *a, const void *b);
|
63 | 64 | /* Was the backup currently in-progress initiated in recovery mode? */
|
64 | 65 | static bool backup_started_in_recovery = false;
|
65 | 66 |
|
| 67 | +/* Relative path of temporary statistics directory */ |
| 68 | +static char *statrelpath = NULL; |
| 69 | + |
66 | 70 | /*
|
67 | 71 | * Size of each block sent into the tar stream for larger files.
|
68 | 72 | */
|
@@ -111,6 +115,18 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
111 | 115 | &labelfile);
|
112 | 116 | SendXlogRecPtrResult(startptr, starttli);
|
113 | 117 |
|
| 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 | + |
114 | 130 | PG_ENSURE_ERROR_CLEANUP(base_backup_cleanup, (Datum) 0);
|
115 | 131 | {
|
116 | 132 | List *tablespaces = NIL;
|
@@ -838,7 +854,6 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
|
838 | 854 | sizeof(PG_AUTOCONF_FILENAME) + 4) == 0)
|
839 | 855 | continue;
|
840 | 856 |
|
841 |
| - |
842 | 857 | /*
|
843 | 858 | * If there's a backup_label file, it belongs to a backup started by
|
844 | 859 | * 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)
|
891 | 906 | continue;
|
892 | 907 | }
|
893 | 908 |
|
| 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 | + |
894 | 923 | /*
|
895 | 924 | * We can skip pg_xlog, the WAL segments need to be fetched from the
|
896 | 925 | * WAL archive anyway. But include it as an empty directory anyway, so
|
|
0 commit comments