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

Appearance settings

Commit 98ec7fd

Browse filesBrowse files
committed
Sync unlogged relations to disk after they have been reset.
Unlogged relations are only reset when performing a unclean restart. That means they have to be synced to disk during clean shutdowns. During normal processing that's achieved by registering a buffer's file to be fsynced at the next checkpoint when flushed. But ResetUnloggedRelations() doesn't go through the buffer manager, so nothing will force reset relations to disk before the next shutdown checkpoint. So just make ResetUnloggedRelations() fsync the newly created main forks to disk. Discussion: 20140912112246.GA4984@alap3.anarazel.de Backpatch to 9.1 where unlogged tables were introduced. Abhijit Menon-Sen and Andres Freund
1 parent d3586fc commit 98ec7fd
Copy full SHA for 98ec7fd

File tree

Expand file treeCollapse file tree

1 file changed

+47
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+47
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/storage/file/reinit.c
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,53 @@ ResetUnloggedRelationsInDbspaceDir(const char *dbspacedirname, int op)
339339
}
340340

341341
FreeDir(dbspace_dir);
342+
343+
/*
344+
* copy_file() above has already called pg_flush_data() on the
345+
* files it created. Now we need to fsync those files, because
346+
* a checkpoint won't do it for us while we're in recovery. We
347+
* do this in a separate pass to allow the kernel to perform
348+
* all the flushes (especially the metadata ones) at once.
349+
*/
350+
dbspace_dir = AllocateDir(dbspacedirname);
351+
if (dbspace_dir == NULL)
352+
{
353+
/* we just saw this directory, so it really ought to be there */
354+
elog(LOG,
355+
"could not open dbspace directory \"%s\": %m",
356+
dbspacedirname);
357+
return;
358+
}
359+
360+
while ((de = ReadDir(dbspace_dir, dbspacedirname)) != NULL)
361+
{
362+
ForkNumber forkNum;
363+
int oidchars;
364+
char oidbuf[OIDCHARS + 1];
365+
char mainpath[MAXPGPATH];
366+
367+
/* Skip anything that doesn't look like a relation data file. */
368+
if (!parse_filename_for_nontemp_relation(de->d_name, &oidchars,
369+
&forkNum))
370+
continue;
371+
372+
/* Also skip it unless this is the init fork. */
373+
if (forkNum != INIT_FORKNUM)
374+
continue;
375+
376+
/* Construct main fork pathname. */
377+
memcpy(oidbuf, de->d_name, oidchars);
378+
oidbuf[oidchars] = '\0';
379+
snprintf(mainpath, sizeof(mainpath), "%s/%s%s",
380+
dbspacedirname, oidbuf, de->d_name + oidchars + 1 +
381+
strlen(forkNames[INIT_FORKNUM]));
382+
383+
fsync_fname(mainpath, false);
384+
}
385+
386+
FreeDir(dbspace_dir);
387+
388+
fsync_fname((char *) dbspacedirname, true);
342389
}
343390
}
344391

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.