[PATCH] Atomic pgrename on Windows
От | Alexander Korotkov |
---|---|
Тема | [PATCH] Atomic pgrename on Windows |
Дата | |
Msg-id | CAPpHfds7dyuGZt+PF2GL9qSSVV0OZnjNwqiCPjN7mirDw882tA@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: [PATCH] Atomic pgrename on Windows
Re: [PATCH] Atomic pgrename on Windows Re: [PATCH] Atomic pgrename on Windows |
Список | pgsql-hackers |
Hi!
It's assumed in PostgreSQL codebase that pgrename atomically replaces target file with source file even if target file is open and being read by another process. And this assumption is true on Linux, but it's false on Windows. MoveFileEx() triggers an error when target file is open (and accordingly locked). Some our customers has been faced such errors while operating heavily loaded PostgreSQL instance on Windows.
I've managed to reproduce this situation. Reliable reproducing of this issue required patch to PostgreSQL core. I've written slow-read-statfiles.patch for artificial slowdown of pgstat_read_statsfiles() – sleep 100 ms after each statfile entry. If you run make-100-dbs.sql on patched version, and then few times execute
in psql, then you would likely get the error above on Windows.
Attached patch atomic-pgrename-windows-1.patch fixes this problem. It appears to be possible to atomically replace file on Windows – ReplaceFile() does that. ReplaceFiles() requires target file to exist, this is why we still need to call MoveFileEx() when it doesn't exist.
This patch is based on work of Victor Spirin who was asked by Postgres Pro to research this problem.
------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Вложения
В списке pgsql-hackers по дате отправления: