pg_rewind fails if there is a read only file. - Mailing list pgsql-hackers

From Paul Guo
Subject pg_rewind fails if there is a read only file.
Date
Msg-id CABQrizcU8FTZG_OUJ8b2bV+h9Roqhs1DuSyvNapV6xwu1cHDJA@mail.gmail.com
Whole thread Raw
Responses Re: pg_rewind fails if there is a read only file.
List 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)



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Refactor "mutually exclusive options" error reporting code in parse_subscription_options
Next
From: Bharath Rupireddy
Date:
Subject: Re: Inaccurate error message when set fdw batch_size to 0