pg_rewind fails if there is a read only file.

From: Paul Guo <paulguo(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>
Subject: pg_rewind fails if there is a read only file.
Date: 2021-05-19 10:43:46
Message-ID: CABQrizcU8FTZG_OUJ8b2bV+h9Roqhs1DuSyvNapV6xwu1cHDJA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Several weeks ago I saw this issue in a production environment. The
read only file looks like a credential file. Michael told me that
usually such kinds of files should be better kept in non-pgdata
directories in production environments. Thought further it seems that
pg_rewind should be more user friendly to tolerate such scenarios.

The failure error is "Permission denied" after open(). The reason is
open() fais with the below mode in open_target_file()

mode = O_WRONLY | O_CREAT | PG_BINARY;
if (trunc)
mode |= O_TRUNC;
dstfd = open(dstpath, mode, pg_file_create_mode);

The fix should be quite simple, if open fails with "Permission denied"
then we try to call chmod to add a S_IWUSR just before open() and call
chmod to reset the flags soon after open(). A stat() call to get
previous st_mode flags is needed.

Any other suggestions or thoughts?

Thanks,

--
Paul Guo (Vmware)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2021-05-19 11:01:06 Re: Inaccurate error message when set fdw batch_size to 0
Previous Message Amit Kapila 2021-05-19 10:40:33 Re: Refactor "mutually exclusive options" error reporting code in parse_subscription_options