BUG #16982: pg_rewind cannot deal with configuration files (postgresql.conf) located outside data directory

Started by PG Bug reporting formover 5 years ago2 messagesbugs
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t70706
psql -h localhost -U postgres

Built from patchset v2 (message #2), July 27, 2026 at 05:07 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t70706_2 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t70706_2 && git checkout t70706_2

Patchset v2 (message #2) is on t70706_2

Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

The following bug has been logged on the website:

Bug reference: 16982
Logged by: Edwin Polkerman
Email address: edwin.polkerman@splendiddata.com
PostgreSQL version: 13.2
Operating system: Centos7/8, RHEL7/8, SUSE12/15
Description:

In the used PostgreSQL setup the configuration files (postgresql.conf,
pg_hha.conf and pg_ident.conf) are located in another location than the data
directory: /etc/database/postgres/13/data

In postgresql.conf following locations are updated:
#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------

# The default values of these variables are driven from the -D
command-line
# option or PGDATA environment variable, represented here as ConfigDir.
data_directory = '/var/database/postgres/13/data'
hba_file = '/etc/database/postgres/13/data/pg_hba.conf'

ident_file = '/etc/database/postgres/13/data/pg_ident.conf'

The cluster can be started with pg_ctl and use the path to postgresql.conf
in -D:

pg_ctl -D /etc/database/postgres/13/data start

Trying to use pg_rewind to synchronize a PostgreSQL data directory (e.g.
bringing back failed master)

pg_rewind --target-pgdata=/etc/database/postgres/13/data -P -R -c

--source-server='host=<ip-address source> port=5432 user=rewind_user
password=rewind_user dbname=postgres'

Observed result:
==========
pg_rewind: connected to server
pg_rewind: fatal: could not open file
"/etc/database/postgres/13/data/global/pg_control" for reading: No such file
or directory

Change --target-pgdata to point to data directory:

pg_rewind --target-pgdata=/var/database/postgres/13/data -P -R -c

--source-server='host=<ip-address source> port=5432 user=rewind_user
password=rewind_user dbname=postgres'

Now the result is:
pg_rewind: fatal: restore_command is not set in the target cluster

Which is another proof that pg_rewind does not look at
/etc/database/postgres/13/data/postgresql.conf (in which restore_command was
set) but to the one located in the data directory.

Improvement:
It would be nice to have pg_rewind support postgresql.conf being located
somewhere else than in the data directory, just like pg_ctl does.

Of course it is possible to workaround the issue but it takes more steps
than would be necessary (with increased error risk of copying and moving
configuration files around).

Not only applicable for PostgreSQL 13, but also for the other versions as
well

#2Neil Chen
carpenter.nail.cz@gmail.com
In reply to: PG Bug reporting form (#1)
Re: BUG #16982: pg_rewind cannot deal with configuration files (postgresql.conf) located outside data directory

Greetings,

On Wed, Apr 28, 2021 at 11:38 AM PG Bug reporting form <
noreply@postgresql.org> wrote:

In the used PostgreSQL setup the configuration files (postgresql.conf,
pg_hha.conf and pg_ident.conf) are located in another location than the
data
directory: /etc/database/postgres/13/data

In postgresql.conf following locations are updated:

#------------------------------------------------------------------------------
# FILE LOCATIONS

#------------------------------------------------------------------------------

# The default values of these variables are driven from the -D
command-line
# option or PGDATA environment variable, represented here as ConfigDir.
data_directory = '/var/database/postgres/13/data'
hba_file = '/etc/database/postgres/13/data/pg_hba.conf'

ident_file = '/etc/database/postgres/13/data/pg_ident.conf'

The cluster can be started with pg_ctl and use the path to postgresql.conf
in -D:

pg_ctl -D /etc/database/postgres/13/data start

Trying to use pg_rewind to synchronize a PostgreSQL data directory (e.g.
bringing back failed master)

pg_rewind --target-pgdata=/etc/database/postgres/13/data -P -R -c

--source-server='host=<ip-address source> port=5432 user=rewind_user
password=rewind_user dbname=postgres'

Observed result:
==========
pg_rewind: connected to server
pg_rewind: fatal: could not open file
"/etc/database/postgres/13/data/global/pg_control" for reading: No such
file
or directory

Improvement:
It would be nice to have pg_rewind support postgresql.conf being located
somewhere else than in the data directory, just like pg_ctl does.

Of course it is possible to workaround the issue but it takes more steps
than would be necessary (with increased error risk of copying and moving
configuration files around).

Not only applicable for PostgreSQL 13, but also for the other versions as
well

Yes, I think in general, pg_rewind should also support this function. To
support it, you can copy the relevant code directly from pg_ctl, here is
the patch.
But of course, I hope to listen to other people's opinions, so that we can
understand why we didn't support this function before, and whether there
are any risks...

Thanks.
--
There is no royal road to learning.
HighGo Software Co.

Attachments:

t70706_2
0001-pg_rewind-patch.patchapplication/octet-stream; name=0001-pg_rewind-patch.patchDownload+101-2