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

Commit26a4e0e

Browse files
committed
Fix initdb --sync-only to also sync tablespaces.
630cd14 added initdb --sync-only, for use by pg_upgrade, by justexposing the existing fsync code. That's wrong, because initdb so farhad absolutely no reason to deal with tablespaces.Fix --sync-only by additionally explicitly syncing each of thetablespaces.Backpatch to 9.3 where --sync-only was introduced.Abhijit Menon-Sen and Andres Freund
1 parent2c3ebfd commit26a4e0e

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include<signal.h>
5757
#include<time.h>
5858

59+
#include"common/relpath.h"
5960
#include"mb/pg_wchar.h"
6061
#include"getaddrinfo.h"
6162
#include"getopt_long.h"
@@ -210,6 +211,7 @@ static char **filter_lines_with_token(char **lines, const char *token);
210211
staticchar**readfile(constchar*path);
211212
staticvoidwritefile(char*path,char**lines);
212213
staticvoidwalkdir(char*path,void (*action) (char*fname,boolisdir));
214+
staticvoidwalktblspc_links(char*path,void (*action) (char*fname,boolisdir));
213215
staticvoidpre_sync_fname(char*fname,boolisdir);
214216
staticvoidfsync_fname(char*fname,boolisdir);
215217
staticFILE*popen_check(constchar*command,constchar*mode);
@@ -585,6 +587,55 @@ walkdir(char *path, void (*action) (char *fname, bool isdir))
585587
(*action) (path, true);
586588
}
587589

590+
/*
591+
* walktblspc_links: call walkdir on each entry under the given
592+
* pg_tblspc directory, or do nothing if pg_tblspc doesn't exist.
593+
*/
594+
staticvoid
595+
walktblspc_links(char*path,void (*action) (char*fname,boolisdir))
596+
{
597+
DIR*dir;
598+
structdirent*direntry;
599+
charsubpath[MAXPGPATH];
600+
601+
dir=opendir(path);
602+
if (dir==NULL)
603+
{
604+
if (errno==ENOENT)
605+
return;
606+
fprintf(stderr,_("%s: could not open directory \"%s\": %s\n"),
607+
progname,path,strerror(errno));
608+
exit_nicely();
609+
}
610+
611+
while (errno=0, (direntry=readdir(dir))!=NULL)
612+
{
613+
if (strcmp(direntry->d_name,".")==0||
614+
strcmp(direntry->d_name,"..")==0)
615+
continue;
616+
617+
/* fsync the version specific tablespace subdirectory */
618+
snprintf(subpath,sizeof(subpath),"%s/%s/%s",
619+
path,direntry->d_name,TABLESPACE_VERSION_DIRECTORY);
620+
621+
walkdir(subpath,action);
622+
}
623+
624+
if (errno)
625+
{
626+
fprintf(stderr,_("%s: could not read directory \"%s\": %s\n"),
627+
progname,path,strerror(errno));
628+
exit_nicely();
629+
}
630+
631+
if (closedir(dir))
632+
{
633+
fprintf(stderr,_("%s: could not close directory \"%s\": %s\n"),
634+
progname,path,strerror(errno));
635+
exit_nicely();
636+
}
637+
}
638+
588639
/*
589640
* Hint to the OS that it should get ready to fsync() this file.
590641
*/
@@ -2311,6 +2362,7 @@ static void
23112362
perform_fsync(void)
23122363
{
23132364
charpdir[MAXPGPATH];
2365+
charpg_tblspc[MAXPGPATH];
23142366

23152367
fputs(_("syncing data to disk ... "),stdout);
23162368
fflush(stdout);
@@ -2329,19 +2381,26 @@ perform_fsync(void)
23292381
/* first the parent of the PGDATA directory */
23302382
pre_sync_fname(pdir, true);
23312383

2332-
/* then recursively through the directory */
2384+
/* then recursively through thedatadirectory */
23332385
walkdir(pg_data,pre_sync_fname);
23342386

2387+
/* now do the same thing for everything under pg_tblspc */
2388+
snprintf(pg_tblspc,MAXPGPATH,"%s/pg_tblspc",pg_data);
2389+
walktblspc_links(pg_tblspc,pre_sync_fname);
2390+
23352391
/*
23362392
* Now, do the fsync()s in the same order.
23372393
*/
23382394

23392395
/* first the parent of the PGDATA directory */
23402396
fsync_fname(pdir, true);
23412397

2342-
/* then recursively through the directory */
2398+
/* then recursively through thedatadirectory */
23432399
walkdir(pg_data,fsync_fname);
23442400

2401+
/* and now the same for all tablespaces */
2402+
walktblspc_links(pg_tblspc,fsync_fname);
2403+
23452404
check_ok();
23462405
}
23472406

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp