Skip to content

Commit 672b43e

Browse files
committed
Ensure unlogged tables are reset even if crash recovery errors out.
Unlogged relations are reset at the end of crash recovery as they're only synced to disk during a proper shutdown. Unfortunately that and later steps can fail, e.g. due to running out of space. This reset was, up to now performed after marking the database as having finished crash recovery successfully. As out of space errors trigger a crash restart that could lead to the situation that not all unlogged relations are reset. Once that happend usage of unlogged relations could yield errors like "could not open file "...": No such file or directory". Luckily clusters that show the problem can be fixed by performing a immediate shutdown, and starting the database again. To fix, just call ResetUnloggedRelations(UNLOGGED_RELATION_INIT) earlier, before marking the database as having successfully recovered. Discussion: [email protected] Backpatch to 9.1 where unlogged tables were introduced. Abhijit Menon-Sen and Andres Freund
1 parent c7299d3 commit 672b43e

File tree

1 file changed

+10
-8
lines changed
  • src/backend/access/transam

1 file changed

+10
-8
lines changed

src/backend/access/transam/xlog.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -5760,6 +5760,16 @@ StartupXLOG(void)
57605760
*/
57615761
ShutdownWalRcv();
57625762

5763+
/*
5764+
* Reset unlogged relations to the contents of their INIT fork. This is
5765+
* done AFTER recovery is complete so as to include any unlogged relations
5766+
* created during recovery, but BEFORE recovery is marked as having
5767+
* completed successfully. Otherwise we'd not retry if any of the post
5768+
* end-of-recovery steps fail.
5769+
*/
5770+
if (InRecovery)
5771+
ResetUnloggedRelations(UNLOGGED_RELATION_INIT);
5772+
57635773
/*
57645774
* We don't need the latch anymore. It's not strictly necessary to disown
57655775
* it, but let's do it for the sake of tidiness.
@@ -6047,14 +6057,6 @@ StartupXLOG(void)
60476057
*/
60486058
PreallocXlogFiles(EndOfLog);
60496059

6050-
/*
6051-
* Reset initial contents of unlogged relations. This has to be done
6052-
* AFTER recovery is complete so that any unlogged relations created
6053-
* during recovery also get picked up.
6054-
*/
6055-
if (InRecovery)
6056-
ResetUnloggedRelations(UNLOGGED_RELATION_INIT);
6057-
60586060
/*
60596061
* Okay, we're officially UP.
60606062
*/

0 commit comments

Comments
 (0)