Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
1331cc6c
Commit
1331cc6c
authored
May 11, 2012
by
Robert Haas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent loss of init fork when truncating an unlogged table.
Fixes bug #6635, reported by Akira Kurosawa.
parent
b762e8f5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
15 deletions
+23
-15
src/backend/catalog/heap.c
src/backend/catalog/heap.c
+17
-15
src/backend/commands/tablecmds.c
src/backend/commands/tablecmds.c
+4
-0
src/include/catalog/heap.h
src/include/catalog/heap.h
+2
-0
No files found.
src/backend/catalog/heap.c
View file @
1331cc6c
...
...
@@ -1306,24 +1306,10 @@ heap_create_with_catalog(const char *relname,
if
(
oncommit
!=
ONCOMMIT_NOOP
)
register_on_commit_action
(
relid
,
oncommit
);
/*
* If this is an unlogged relation, it needs an init fork so that it can
* be correctly reinitialized on restart. Since we're going to do an
* immediate sync, we only need to xlog this if archiving or streaming is
* enabled. And the immediate sync is required, because otherwise there's
* no guarantee that this will hit the disk before the next checkpoint
* moves the redo pointer.
*/
if
(
relpersistence
==
RELPERSISTENCE_UNLOGGED
)
{
Assert
(
relkind
==
RELKIND_RELATION
||
relkind
==
RELKIND_TOASTVALUE
);
RelationOpenSmgr
(
new_rel_desc
);
smgrcreate
(
new_rel_desc
->
rd_smgr
,
INIT_FORKNUM
,
false
);
if
(
XLogIsNeeded
())
log_smgrcreate
(
&
new_rel_desc
->
rd_smgr
->
smgr_rnode
.
node
,
INIT_FORKNUM
);
smgrimmedsync
(
new_rel_desc
->
rd_smgr
,
INIT_FORKNUM
);
heap_create_init_fork
(
new_rel_desc
);
}
/*
...
...
@@ -1336,6 +1322,22 @@ heap_create_with_catalog(const char *relname,
return
relid
;
}
/*
* Set up an init fork for an unlogged table so that it can be correctly
* reinitialized on restart. Since we're going to do an immediate sync, we
* only need to xlog this if archiving or streaming is enabled. And the
* immediate sync is required, because otherwise there's no guarantee that
* this will hit the disk before the next checkpoint moves the redo pointer.
*/
void
heap_create_init_fork
(
Relation
rel
)
{
RelationOpenSmgr
(
rel
);
smgrcreate
(
rel
->
rd_smgr
,
INIT_FORKNUM
,
false
);
if
(
XLogIsNeeded
())
log_smgrcreate
(
&
rel
->
rd_smgr
->
smgr_rnode
.
node
,
INIT_FORKNUM
);
smgrimmedsync
(
rel
->
rd_smgr
,
INIT_FORKNUM
);
}
/*
* RelationRemoveInheritance
...
...
src/backend/commands/tablecmds.c
View file @
1331cc6c
...
...
@@ -1155,6 +1155,8 @@ ExecuteTruncate(TruncateStmt *stmt)
* deletion at commit.
*/
RelationSetNewRelfilenode
(
rel
,
RecentXmin
);
if
(
rel
->
rd_rel
->
relpersistence
==
RELPERSISTENCE_UNLOGGED
)
heap_create_init_fork
(
rel
);
heap_relid
=
RelationGetRelid
(
rel
);
toast_relid
=
rel
->
rd_rel
->
reltoastrelid
;
...
...
@@ -1166,6 +1168,8 @@ ExecuteTruncate(TruncateStmt *stmt)
{
rel
=
relation_open
(
toast_relid
,
AccessExclusiveLock
);
RelationSetNewRelfilenode
(
rel
,
RecentXmin
);
if
(
rel
->
rd_rel
->
relpersistence
==
RELPERSISTENCE_UNLOGGED
)
heap_create_init_fork
(
rel
);
heap_close
(
rel
,
NoLock
);
}
...
...
src/include/catalog/heap.h
View file @
1331cc6c
...
...
@@ -69,6 +69,8 @@ extern Oid heap_create_with_catalog(const char *relname,
bool
use_user_acl
,
bool
allow_system_table_mods
);
extern
void
heap_create_init_fork
(
Relation
rel
);
extern
void
heap_drop_with_catalog
(
Oid
relid
);
extern
void
heap_truncate
(
List
*
relids
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment