Skip to content

Commit e85e459

Browse files
committed
Do not backup files of the unlogged relations (only leave _init fork)
1 parent 14e5110 commit e85e459

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

src/backup.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,13 +1990,15 @@ backup_files(void *arg)
19901990
/*
19911991
* Extract information about files in backup_list parsing their names:
19921992
* - remove temp tables from the list
1993+
* - remove unlogged tables from the list (leave the _init fork)
19931994
* - set flags for database directories
19941995
* - set flags for datafiles
19951996
*/
19961997
static void
19971998
parse_backup_filelist_filenames(parray *files, const char *root)
19981999
{
19992000
size_t i;
2001+
Oid unlogged_file_reloid = 0;
20002002

20012003
for (i = 0; i < parray_num(files); i++)
20022004
{
@@ -2157,13 +2159,46 @@ parse_backup_filelist_filenames(parray *files, const char *root)
21572159
/* auxiliary fork of the relfile */
21582160
sscanf(filename, "%u_%s", &(file->relOid), file->forkName);
21592161
elog(VERBOSE, "relOid %u, forkName %s, filepath %s", file->relOid, file->forkName, relative);
2160-
if (strcmp(file->forkName, "ptrack") == 0)
2162+
2163+
/* handle unlogged relations */
2164+
if (strcmp(file->forkName, "init") == 0)
2165+
{
2166+
/*
2167+
* Do not backup files of unlogged relations.
2168+
* scan filelist backward and exclude these files.
2169+
*/
2170+
int unlogged_file_num = i-1;
2171+
pgFile *unlogged_file = (pgFile *) parray_get(files, unlogged_file_num);
2172+
2173+
unlogged_file_reloid = file->relOid;
2174+
2175+
while (unlogged_file_num >= 0 &&
2176+
(unlogged_file_reloid != 0) &&
2177+
(unlogged_file->relOid == unlogged_file_reloid))
2178+
{
2179+
unlogged_file->size = 0;
2180+
pgFileFree(unlogged_file);
2181+
parray_remove(files, unlogged_file_num);
2182+
unlogged_file_num--;
2183+
i--;
2184+
unlogged_file = (pgFile *) parray_get(files, unlogged_file_num);
2185+
}
2186+
}
2187+
else if (strcmp(file->forkName, "ptrack") == 0)
21612188
{
21622189
/* Do not backup ptrack files */
21632190
pgFileFree(file);
21642191
parray_remove(files, i);
21652192
i--;
21662193
}
2194+
else if ((unlogged_file_reloid != 0) &&
2195+
(file->relOid == unlogged_file_reloid))
2196+
{
2197+
/* Do not backup forks of unlogged relations */
2198+
pgFileFree(file);
2199+
parray_remove(files, i);
2200+
i--;
2201+
}
21672202
continue;
21682203
}
21692204

@@ -2201,6 +2236,15 @@ parse_backup_filelist_filenames(parray *files, const char *root)
22012236
*/
22022237
elog(VERBOSE, "relOid %u, segno %d, suffix %s, filepath %s", file->relOid, file->segno, suffix, relative);
22032238
}
2239+
2240+
if ((unlogged_file_reloid != 0) &&
2241+
(file->relOid == unlogged_file_reloid))
2242+
{
2243+
/* Do not backup segments of unlogged files */
2244+
pgFileFree(file);
2245+
parray_remove(files, i);
2246+
i--;
2247+
}
22042248
}
22052249
}
22062250
}

0 commit comments

Comments
 (0)