Skip to content

Commit ea8b383

Browse 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 c5baa70 commit ea8b383

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/backend/storage/file/reinit.c

Lines 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
/* Done with the first pass. */
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy