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

Commit78c24e9

Browse files
committed
Fix concurrency issues with WAL segment recycling on Windows
This commit is mostly a revert ofaaa3aed, that switched the routinedoing the internal renaming of recycled WAL segments to use on Windows acombination of CreateHardLinkA() plus unlink() instead of rename(). Asreported by several users of Postgres 13, this is causing concurrencyissues when manipulating WAL segments, mostly in the shape of thefollowing error:LOG: could not rename file "pg_wal/000000XX000000YY000000ZZ":Permission deniedThis moves back to a logic where a single rename() (well, pgrename() forWindows) is used. This issue has proved to be hard to hit when I testedit, facing it only once with an archive_command that was not able to doits work, so it is environment-sensitive. The reporters of this issuehave been able to confirm that the situation improved once we switchedback to a single rename(). In order to check things, I have provided tothe reporters a patched build based on 13.2 withaaa3aed reverted, totest if the error goes away, and an unpatched build of 13.2 to test ifthe error still showed up (just to make sure that I did not mess up mybuild process).Extra thanks to Fujii Masao for pointing out what looked like theculprit commit, and to all the reporters for taking the time to testwhat I have sent them.Reported-by: Andrus, Guy Burgess, Yaroslav Pashinsky, Thomas TrenzReviewed-by: Tom Lane, Andres FreundDiscussion:https://postgr.es/m/3861ff1e-0923-7838-e826-094cc9bef737@hot.eeDiscussion:https://postgr.es/m/16874-c3eecd319e36a2bf@postgresql.orgDiscussion:https://postgr.es/m/095ccf8d-7f58-d928-427c-b17ace23cae6@burgess.co.nzDiscussion:https://postgr.es/m/16927-67c570d968c99567%40postgresql.orgDiscussion:https://postgr.es/m/YFBcRbnBiPdGZvfW@paquier.xyzBackpatch-through: 13
1 parent48664e4 commit78c24e9

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,17 +767,20 @@ durable_unlink(const char *fname, int elevel)
767767
}
768768

769769
/*
770-
* durable_rename_excl -- rename a file in a durable manner, without
771-
* overwriting an existing target file
770+
* durable_rename_excl -- rename a file in a durable manner.
772771
*
773-
* Similar to durable_rename(), except that this routinewill fail if the
774-
*target file already exists.
772+
* Similar to durable_rename(), except that this routinetries (but does not
773+
*guarantee) not to overwrite the target file.
775774
*
776775
* Note that a crash in an unfortunate moment can leave you with two links to
777776
* the target file.
778777
*
779778
* Log errors with the caller specified severity.
780779
*
780+
* On Windows, using a hard link followed by unlink() causes concurrency
781+
* issues, while a simple rename() does not cause that, so be careful when
782+
* changing the logic of this routine.
783+
*
781784
* Returns 0 if the operation succeeded, -1 otherwise. Note that errno is not
782785
* valid upon return.
783786
*/
@@ -791,6 +794,7 @@ durable_rename_excl(const char *oldfile, const char *newfile, int elevel)
791794
if (fsync_fname_ext(oldfile, false, false,elevel)!=0)
792795
return-1;
793796

797+
#ifdefHAVE_WORKING_LINK
794798
if (link(oldfile,newfile)<0)
795799
{
796800
ereport(elevel,
@@ -800,6 +804,16 @@ durable_rename_excl(const char *oldfile, const char *newfile, int elevel)
800804
return-1;
801805
}
802806
unlink(oldfile);
807+
#else
808+
if (rename(oldfile,newfile)<0)
809+
{
810+
ereport(elevel,
811+
(errcode_for_file_access(),
812+
errmsg("could not rename file \"%s\" to \"%s\": %m",
813+
oldfile,newfile)));
814+
return-1;
815+
}
816+
#endif
803817

804818
/*
805819
* Make change persistent in case of an OS crash, both the new entry and

‎src/include/pg_config_manual.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@
135135
#defineEXEC_BACKEND
136136
#endif
137137

138+
/*
139+
* Define this if your operating system supports link()
140+
*/
141+
#if !defined(WIN32)&& !defined(__CYGWIN__)
142+
#defineHAVE_WORKING_LINK 1
143+
#endif
144+
138145
/*
139146
* USE_POSIX_FADVISE controls whether Postgres will attempt to use the
140147
* posix_fadvise() kernel call. Usually the automatic configure tests are

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp