Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit920a5e5

Browse files
committed
Skip temp tables from basebackup.
Do not store temp tables in basebackup, they will not be visible anyway, so,there are not reasons to store them.Author: David SteelReviewed by: meDiscussion:https://www.postgresql.org/message-id/flat/5ea4d26a-a453-c1b7-eff9-5a3ef8f8aceb@pgmasters.net
1 parent3ad5586 commit920a5e5

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

‎doc/src/sgml/protocol.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ The commands accepted in replication mode are:
25652565
<para>
25662566
Various temporary files and directories created during the operation
25672567
of the PostgreSQL server, such as any file or directory beginning
2568-
with <filename>pgsql_tmp</filename>.
2568+
with <filename>pgsql_tmp</filename> and temporary relations.
25692569
</para>
25702570
</listitem>
25712571
<listitem>

‎src/backend/replication/basebackup.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,16 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
10721072
}
10731073
}
10741074

1075+
/* Exclude temporary relations */
1076+
if (isDbDir&&looks_like_temp_rel_name(de->d_name))
1077+
{
1078+
elog(DEBUG2,
1079+
"temporary relation file \"%s\" excluded from backup",
1080+
de->d_name);
1081+
1082+
continue;
1083+
}
1084+
10751085
snprintf(pathbuf,sizeof(pathbuf),"%s/%s",path,de->d_name);
10761086

10771087
/* Skip pg_control here to back up it last */

‎src/backend/storage/file/fd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ static void RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok,
325325
boolunlink_all);
326326
staticvoidRemovePgTempRelationFiles(constchar*tsdirname);
327327
staticvoidRemovePgTempRelationFilesInDbspace(constchar*dbspacedirname);
328-
staticboollooks_like_temp_rel_name(constchar*name);
329328

330329
staticvoidwalkdir(constchar*path,
331330
void (*action) (constchar*fname,boolisdir,intelevel),
@@ -3192,7 +3191,7 @@ RemovePgTempRelationFilesInDbspace(const char *dbspacedirname)
31923191
}
31933192

31943193
/* t<digits>_<digits>, or t<digits>_<digits>_<forkname> */
3195-
staticbool
3194+
bool
31963195
looks_like_temp_rel_name(constchar*name)
31973196
{
31983197
intpos;

‎src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
use warnings;
33
use Cwd;
44
use Config;
5+
use File::Basenameqw(basename dirname);
56
use PostgresNode;
67
use TestLib;
7-
use Test::Moretests=>87;
8+
use Test::Moretests=>93;
89

910
program_help_ok('pg_basebackup');
1011
program_version_ok('pg_basebackup');
@@ -76,6 +77,18 @@
7677
ok(-f"$pgdata/${baseUnloggedPath}_init",'unlogged init fork in base');
7778
ok(-f"$pgdata/$baseUnloggedPath",'unlogged main fork in base');
7879

80+
# Create files that look like temporary relations to ensure they are ignored.
81+
my$postgresOid =$node->safe_psql('postgres',
82+
q{select oid from pg_database where datname = 'postgres'});
83+
84+
my@tempRelationFiles =qw(t999_999 t9999_999.1 t999_9999_vm t99999_99999_vm.1);
85+
86+
foreachmy$filename (@tempRelationFiles)
87+
{
88+
append_to_file("$pgdata/base/$postgresOid/$filename",'TEMP_RELATION');
89+
}
90+
91+
# Run base backup.
7992
$node->command_ok(['pg_basebackup','-D',"$tempdir/backup",'-X','none' ],
8093
'pg_basebackup runs');
8194
ok(-f"$tempdir/backup/PG_VERSION",'backup was created');
@@ -112,6 +125,13 @@
112125
ok(!-f"$tempdir/backup/$baseUnloggedPath",
113126
'unlogged main fork not in backup');
114127

128+
# Temp relations should not be copied.
129+
foreachmy$filename (@tempRelationFiles)
130+
{
131+
ok(!-f"$tempdir/backup/base/$postgresOid/$filename",
132+
"base/$postgresOid/$filename not copied");
133+
}
134+
115135
# Make sure existing backup_label was ignored.
116136
isnt(slurp_file("$tempdir/backup/backup_label"),
117137
'DONOTCOPY','existing backup_label not copied');
@@ -206,6 +226,19 @@
206226
ok(-f"$pgdata/$tblspc1UnloggedPath",
207227
'unlogged main fork in tablespace');
208228

229+
# Create files that look like temporary relations to ensure they are ignored
230+
# in a tablespace.
231+
my@tempRelationFiles =qw(t888_888 t888888_888888_vm.1);
232+
my$tblSpc1Id = basename(dirname(dirname($node->safe_psql('postgres',
233+
q{select pg_relation_filepath('test1')}))));
234+
235+
foreachmy$filename (@tempRelationFiles)
236+
{
237+
append_to_file(
238+
"$shorter_tempdir/tblspc1/$tblSpc1Id/$postgresOid/$filename",
239+
'TEMP_RELATION');
240+
}
241+
209242
$node->command_fails(
210243
['pg_basebackup','-D',"$tempdir/backup1",'-Fp' ],
211244
'plain format with tablespaces fails without tablespace mapping');
@@ -232,6 +265,20 @@
232265
ok(!-f"$tempdir/tbackup/tblspc1/$tblspc1UnloggedBackupPath",
233266
'unlogged main fork not in tablespace backup');
234267

268+
# Temp relations should not be copied.
269+
foreachmy$filename (@tempRelationFiles)
270+
{
271+
ok(!-f"$tempdir/tbackup/tblspc1/$tblSpc1Id/$postgresOid/$filename",
272+
"[tblspc1]/$postgresOid/$filename not copied");
273+
274+
# Also remove temp relation files or tablespace drop will fail.
275+
my$filepath =
276+
"$shorter_tempdir/tblspc1/$tblSpc1Id/$postgresOid/$filename";
277+
278+
unlink($filepath)
279+
or BAIL_OUT("unable to unlink$filepath");
280+
}
281+
235282
ok(-d"$tempdir/backup1/pg_replslot",
236283
'pg_replslot symlink copied as directory');
237284

‎src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ extern void AtEOXact_Files(void);
124124
externvoidAtEOSubXact_Files(boolisCommit,SubTransactionIdmySubid,
125125
SubTransactionIdparentSubid);
126126
externvoidRemovePgTempFiles(void);
127+
externboollooks_like_temp_rel_name(constchar*name);
127128

128129
externintpg_fsync(intfd);
129130
externintpg_fsync_no_writethrough(intfd);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp