Skip to content

[Bug] postgresql.base.conf file not properly removed leads to incorrect data dir #936

@snoby

Description

@snoby

Bug description

Patroni can not start because postgres is starting on the wrong data directory. All the config files are correct however system is pointed at the wrong directory. This is because the initial cluster was created ( but failed) and still points to the wrong configs

Expected behavior

New cluster should be created and started based upon new configs not old generated configs.

Steps to reproduce

Create a cluster on a Debian cluster where the user changes the postgresql_data_dir to be /data

then upon a write failure to that directory ( for whatever reason). Run the
ansible-playbook remove_cluster.yml -e "remove_postgres=true remove_etcd=true"
command.

now change the vars/Debian.yml file variable postgresql_data_dir to
postgresql_data_dir: "/data/{{ postgresql_version }}/{{ postgresql_cluster_name }}"

create the cluster as usual. Everything will complete properly AND all the config will be correct EXCEPT patroni can not start

Apr 01 11:22:05 atl1-pg-1 patroni[126912]: 2025-04-01 11:22:05 UTC [126912-2]  FATAL:  "/data" is not a valid data directory
Apr 01 11:22:05 atl1-pg-1 patroni[126912]: 2025-04-01 11:22:05 UTC [126912-3]  DETAIL:  File "/data/PG_VERSION" is missing.


After much digging around this is because postgresql.base.conf file still has `data_directory='/data'

cat /etc/postgresql/17/main/postgresql.base.conf

in file postgresql.base.conf

#------------------------------------------------------------------------------
# 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 = '/data/'		# use data in another directory
					# (change requires restart)
hba_file = '/etc/postgresql/17/main/pg_hba.conf'	# host-based authentication file
					# (change requires restart)
ident_file = '/etc/postgresql/17/main/pg_ident.conf'	# ident configuration file
					# (change requires restart)

Installation method

Command line

System info

standard install on ubuntu 24.04 with postgres 17, with etcd
the /data/ directory is actually a mount and the system is running in an 'incus / lxc` container. None of that should matter but adding it here to be complete.

Additional info

Not sure exactly how you want to handle this but i tried
apt-get --purge remove postgresql-17 with a full data purge and that file was still there... so then i took a sledge hammer to it.

rm -rf /etc/postgresql/17/main/

and then did a new cluster install and patroni started, i had to do the same thing on the replica's as well.

After doing these steps the cluster / patroni started and ran.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions