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

Commit98ec7fd

Browse files
committed
Sync unlogged relations to disk after they have been reset.
Unlogged relations are only reset when performing a uncleanrestart. That means they have to be synced to disk during cleanshutdowns. During normal processing that's achieved by registering abuffer's file to be fsynced at the next checkpoint when flushed. ButResetUnloggedRelations() doesn't go through the buffer manager, sonothing will force reset relations to disk before the next shutdowncheckpoint.So just make ResetUnloggedRelations() fsync the newly created mainforks to disk.Discussion: 20140912112246.GA4984@alap3.anarazel.deBackpatch to 9.1 where unlogged tables were introduced.Abhijit Menon-Sen and Andres Freund
1 parentd3586fc commit98ec7fd

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

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+
ForkNumberforkNum;
363+
intoidchars;
364+
charoidbuf[OIDCHARS+1];
365+
charmainpath[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)

[8]ページ先頭

©2009-2025 Movatter.jp