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

Commit2ca6bac

Browse files
committed
Prevent loss of init fork when truncating an unlogged table.
Fixes bug #6635, reported by Akira Kurosawa.
1 parentf93e45d commit2ca6bac

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

‎src/backend/catalog/heap.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,24 +1290,10 @@ heap_create_with_catalog(const char *relname,
12901290
if (oncommit!=ONCOMMIT_NOOP)
12911291
register_on_commit_action(relid,oncommit);
12921292

1293-
/*
1294-
* If this is an unlogged relation, it needs an init fork so that it can
1295-
* be correctly reinitialized on restart. Since we're going to do an
1296-
* immediate sync, we only need to xlog this if archiving or streaming is
1297-
* enabled. And the immediate sync is required, because otherwise there's
1298-
* no guarantee that this will hit the disk before the next checkpoint
1299-
* moves the redo pointer.
1300-
*/
13011293
if (relpersistence==RELPERSISTENCE_UNLOGGED)
13021294
{
13031295
Assert(relkind==RELKIND_RELATION||relkind==RELKIND_TOASTVALUE);
1304-
1305-
RelationOpenSmgr(new_rel_desc);
1306-
smgrcreate(new_rel_desc->rd_smgr,INIT_FORKNUM, false);
1307-
if (XLogIsNeeded())
1308-
log_smgrcreate(&new_rel_desc->rd_smgr->smgr_rnode.node,
1309-
INIT_FORKNUM);
1310-
smgrimmedsync(new_rel_desc->rd_smgr,INIT_FORKNUM);
1296+
heap_create_init_fork(new_rel_desc);
13111297
}
13121298

13131299
/*
@@ -1320,6 +1306,22 @@ heap_create_with_catalog(const char *relname,
13201306
returnrelid;
13211307
}
13221308

1309+
/*
1310+
* Set up an init fork for an unlogged table so that it can be correctly
1311+
* reinitialized on restart. Since we're going to do an immediate sync, we
1312+
* only need to xlog this if archiving or streaming is enabled. And the
1313+
* immediate sync is required, because otherwise there's no guarantee that
1314+
* this will hit the disk before the next checkpoint moves the redo pointer.
1315+
*/
1316+
void
1317+
heap_create_init_fork(Relationrel)
1318+
{
1319+
RelationOpenSmgr(rel);
1320+
smgrcreate(rel->rd_smgr,INIT_FORKNUM, false);
1321+
if (XLogIsNeeded())
1322+
log_smgrcreate(&rel->rd_smgr->smgr_rnode.node,INIT_FORKNUM);
1323+
smgrimmedsync(rel->rd_smgr,INIT_FORKNUM);
1324+
}
13231325

13241326
/*
13251327
*RelationRemoveInheritance

‎src/backend/commands/tablecmds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ ExecuteTruncate(TruncateStmt *stmt)
10591059
* deletion at commit.
10601060
*/
10611061
RelationSetNewRelfilenode(rel,RecentXmin);
1062+
if (rel->rd_rel->relpersistence==RELPERSISTENCE_UNLOGGED)
1063+
heap_create_init_fork(rel);
10621064

10631065
heap_relid=RelationGetRelid(rel);
10641066
toast_relid=rel->rd_rel->reltoastrelid;
@@ -1070,6 +1072,8 @@ ExecuteTruncate(TruncateStmt *stmt)
10701072
{
10711073
rel=relation_open(toast_relid,AccessExclusiveLock);
10721074
RelationSetNewRelfilenode(rel,RecentXmin);
1075+
if (rel->rd_rel->relpersistence==RELPERSISTENCE_UNLOGGED)
1076+
heap_create_init_fork(rel);
10731077
heap_close(rel,NoLock);
10741078
}
10751079

‎src/include/catalog/heap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ extern Oid heap_create_with_catalog(const char *relname,
6565
booluse_user_acl,
6666
boolallow_system_table_mods);
6767

68+
externvoidheap_create_init_fork(Relationrel);
69+
6870
externvoidheap_drop_with_catalog(Oidrelid);
6971

7072
externvoidheap_truncate(List*relids);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp