Skip to content

Commit 758cf19

Browse files
committed
PGPRO-380 #comment Fix cleanup of unlogged compressed tables in postgres database
1 parent 49065c2 commit 758cf19

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/backend/storage/file/copydir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ copy_zip_file(char *fromfile, bool from_compressed,
319319
Assert(sep != NULL);
320320

321321
if ((sscanf(sep+1, "%d.%d%n", &relno, &segno, &n) != 2
322+
&& sscanf(sep+1, "%d_init%n", &relno, &n) != 1
322323
&& sscanf(sep+1, "%d%n", &relno, &n) != 1)
323324
|| sep[n+1] != '\0'
324325
|| relno < FirstNormalObjectId)
@@ -328,7 +329,7 @@ copy_zip_file(char *fromfile, bool from_compressed,
328329
}
329330

330331
if (to_compressed)
331-
fprintf(stderr, "Compress file %s, relno=%d, sep[n+1]=%s\n",
332+
elog(DEBUG2, "Compress file %s, relno=%d, sep[n+1]=%s\n",
332333
tofile, relno, &sep[n+1]);
333334

334335
/* Open the files */

src/backend/storage/file/reinit.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
#include "utils/memutils.h"
2626

2727
static void ResetUnloggedRelationsInTablespaceDir(const char *tsdirname,
28-
int op);
28+
int op, bool compressed);
2929
static void ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname,
30-
int op);
30+
int op, bool compressed);
3131
static bool parse_filename_for_nontemp_relation(const char *name,
3232
int *oidchars, ForkNumber *fork);
3333

@@ -71,7 +71,7 @@ ResetUnloggedRelations(int op)
7171
/*
7272
* First process unlogged files in pg_default ($PGDATA/base)
7373
*/
74-
ResetUnloggedRelationsInTablespaceDir("base", op);
74+
ResetUnloggedRelationsInTablespaceDir("base", op, false);
7575

7676
/*
7777
* Cycle through directories for all non-default tablespaces.
@@ -80,13 +80,25 @@ ResetUnloggedRelations(int op)
8080

8181
while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL)
8282
{
83+
FILE* compressionFile;
84+
8385
if (strcmp(spc_de->d_name, ".") == 0 ||
8486
strcmp(spc_de->d_name, "..") == 0)
8587
continue;
8688

89+
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s/pg_compression",
90+
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY);
91+
92+
compressionFile = fopen(temp_path, "r");
93+
if (compressionFile)
94+
{
95+
fclose(compressionFile);
96+
}
97+
8798
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
8899
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY);
89-
ResetUnloggedRelationsInTablespaceDir(temp_path, op);
100+
101+
ResetUnloggedRelationsInTablespaceDir(temp_path, op, compressionFile != NULL);
90102
}
91103

92104
FreeDir(spc_dir);
@@ -100,7 +112,7 @@ ResetUnloggedRelations(int op)
100112

101113
/* Process one tablespace directory for ResetUnloggedRelations */
102114
static void
103-
ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
115+
ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op, bool compressed)
104116
{
105117
DIR *ts_dir;
106118
struct dirent *de;
@@ -133,15 +145,15 @@ ResetUnloggedRelationsInTablespaceDir(const char *tsdirname, int op)
133145

134146
snprintf(dbspace_path, sizeof(dbspace_path), "%s/%s",
135147
tsdirname, de->d_name);
136-
ResetUnloggedRelationsInDbspaceDir(dbspace_path, op);
148+
ResetUnloggedRelationsInDbspaceDir(dbspace_path, op, compressed);
137149
}
138150

139151
FreeDir(ts_dir);
140152
}
141153

142154
/* Process one per-dbspace directory for ResetUnloggedRelations */
143155
static void
144-
ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
156+
ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op, bool compressed)
145157
{
146158
DIR *dbspace_dir;
147159
struct dirent *de;
@@ -332,8 +344,13 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
332344
strlen(forkNames[INIT_FORKNUM]));
333345

334346
/* OK, we're ready to perform the actual copy. */
335-
elog(DEBUG2, "copying %s to %s", srcpath, dstpath);
336-
copy_file(srcpath, dstpath);
347+
if (compressed) {
348+
elog(DEBUG2, "copying %s to %s with compression", srcpath, dstpath);
349+
copy_zip_file(srcpath, false, dstpath, true);
350+
} else {
351+
elog(DEBUG2, "copying %s to %s", srcpath, dstpath);
352+
copy_file(srcpath, dstpath);
353+
}
337354
}
338355

339356
FreeDir(dbspace_dir);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy