Re: Two started cluster on the same data directory and port

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Loles <lolesft(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Two started cluster on the same data directory and port
Date: 2023-11-30 20:35:34
Message-ID: 1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/30/23 10:35, Adrian Klaver wrote:
> On 11/30/23 09:27, Loles wrote:
>
>> root(at)hostname:~# pg_lsclusters
>> Ver Cluster  Port Status Owner    Data directory              Log file
>> *14  main     5432 online* postgres /var/lib/postgresql/14/main
>> /var/log/postgresql/postgresql-14-main.log
>> *14  main_old 5432 online *postgres /var/lib/postgresql/14/main
>> /var/log/postgresql/postgresql-14-main_old.log
>>
>> Start, up the two cluster.
>>
>
> Before going any further make sure you have a current backup of the
> database.
>
> Hmm, are /etc/postgresql/14/main/ and /etc/postgresql/14/main_old/
> symlinked together?
>
> If not what if you move the ~14/main_old/ directory somewhere else and
> then restart Postgres?

Alright results of testing here:

tree /etc/postgresql/14
/etc/postgresql/14
├── main
│   ├── conf.d
│   ├── environment
│   ├── pg_ctl.conf
│   ├── pg_hba.conf
│   ├── pg_ident.conf
│   ├── postgresql.conf
│   └── start.conf
└── main_old
├── conf.d
├── environment
├── pg_ctl.conf
├── pg_hba.conf
├── pg_ident.conf
├── postgresql.conf
└── start.conf

Where I just copied main/ to main_old/.

sudo pg_ctlcluster start 14 main

pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
14 main 5432 online postgres /var/lib/postgresql/14/main
/var/log/postgresql/postgresql-14-main.log
14 main_old 5432 online postgres /var/lib/postgresql/14/main
/var/log/postgresql/postgresql-14-main_old.log

sudo pg_ctlcluster stop 14 main

pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
14 main 5432 down postgres /var/lib/postgresql/14/main
/var/log/postgresql/postgresql-14-main.log
14 main_old 5432 down postgres /var/lib/postgresql/14/main
/var/log/postgresql/postgresql-14-main_old.log

cd /etc/postgresql/14/
sudo rm -r main_old/
or
sudo cp -r main_old <some_new_path>

sudo pg_ctlcluster start 14 main

pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
14 main 5432 online postgres /var/lib/postgresql/14/main
/var/log/postgresql/postgresql-14-main.log

I would need to understand systemd better to be sure, but I'm thinking
the duplicated cluster are happening here:

/lib/systemd/system-generators/postgresql-generator

#!/bin/sh

# This systemd generator creates dependency symlinks that make all
PostgreSQL
# clusters with "auto" in their start.conf file be started/stopped/reloaded
# when postgresql.service is started/stopped/reloaded.

set -eu

gendir="$1"
wantdir="$1/postgresql.service.wants"
bindir="/usr/lib/postgresql/"
#redhat# bindir="/usr/pgsql-"
pgservice="/lib/systemd/system/postgresql(at)(dot)service"

mkdir -p "$wantdir"

for conf in /etc/postgresql/*/*/postgresql.conf; do
# abort loop if glob was not expanded (but accept dead symlinks)
if ! test -e "$conf" && ! test -L "$conf"; then continue; fi

dir="${conf%/*}"

# evaluate start.conf
if [ -e "$dir/start.conf" ]; then
start=$(sed 's/#.*$//; /^[[:space:]]*$/d; s/^\s*//;
s/\s*$//' "$dir/start.conf")
else
start=auto
fi
[ "$start" = "auto" ] || continue

verdir="${dir%/*}"
version="${verdir##*/}"
test -x "$bindir$version/bin/postgres" || continue # package
got removed
cluster="${dir##*/}"
ln -s "$pgservice" "$wantdir/postgresql(at)$version-$cluster(dot)service"
done

exit 0

>
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Atul Kumar 2023-11-30 20:41:25 replication strange behavior
Previous Message Loles 2023-11-30 20:29:42 Re: Two started cluster on the same data directory and port