pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Loles <lolesft@gmail.com>
Cc: PostgreSQL <pgsql-general@postgresql.org>
Subject: Re: Two started cluster on the same data directory and port
Date: Thu, 30 Nov 2023 12:35:34 -0800
Message-ID: <1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com> (raw)
In-Reply-To: <7280c019-2c61-452c-be52-bf38604df356@aklaver.com>
References: <CA+FWGK4pWAJkxth2nyJ5ZGewfqRCCJ0YJeXe0v8FC1pURuEtbg@mail.gmail.com>
	<477f32ab-72cc-4888-835a-0f25aa3db705@aklaver.com>
	<cf37b994-64af-4c70-8e30-ef9a0e2229bf@aklaver.com>
	<CA+FWGK4ckVnEEDnExYEaiyn2X+Q2YqO8qhUsdwGTX9qCDJV7ZQ@mail.gmail.com>
	<CA+FWGK5BCtYdA5X1bZNFixsxqXU9vXVeS1=ue6h1UHoGs-e9-g@mail.gmail.com>
	<b9b2c6fe-6ca7-4d70-b3cb-3d343a0f47e1@aklaver.com>
	<CA+FWGK4xFPK3HV7p_087oXMH-ewCyTivcXihHEDKTTgt8wQ5VA@mail.gmail.com>
	<10c26017-62f2-457e-b71c-c53eada6ae5b@aklaver.com>
	<CA+FWGK5t6nE3e1fAWc5j1yXEKkDFhP3ZTNUyHRGbxysDN7k7kA@mail.gmail.com>
	<7280c019-2c61-452c-be52-bf38604df356@aklaver.com>

On 11/30/23 10:35, Adrian Klaver wrote:
> On 11/30/23 09:27, Loles wrote:
> 
>> root@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@.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@$version-$cluster.service"
done

exit 0




> 
> Adrian Klaver
> adrian.klaver@aklaver.com
> 
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (17+ messages)  latest in thread

Message-ID: <1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com>
Permalink:  ../1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com/
Also on:    postgresql.org/message-id/1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, lolesft@gmail.com
  Subject: Re: Two started cluster on the same data directory and port
  In-Reply-To: <1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com>
  References: <CA+FWGK4pWAJkxth2nyJ5ZGewfqRCCJ0YJeXe0v8FC1pURuEtbg@mail.gmail.com> <477f32ab-72cc-4888-835a-0f25aa3db705@aklaver.com> <cf37b994-64af-4c70-8e30-ef9a0e2229bf@aklaver.com> <CA+FWGK4ckVnEEDnExYEaiyn2X+Q2YqO8qhUsdwGTX9qCDJV7ZQ@mail.gmail.com> <CA+FWGK5BCtYdA5X1bZNFixsxqXU9vXVeS1=ue6h1UHoGs-e9-g@mail.gmail.com> <b9b2c6fe-6ca7-4d70-b3cb-3d343a0f47e1@aklaver.com> <CA+FWGK4xFPK3HV7p_087oXMH-ewCyTivcXihHEDKTTgt8wQ5VA@mail.gmail.com> <10c26017-62f2-457e-b71c-c53eada6ae5b@aklaver.com> <CA+FWGK5t6nE3e1fAWc5j1yXEKkDFhP3ZTNUyHRGbxysDN7k7kA@mail.gmail.com> <7280c019-2c61-452c-be52-bf38604df356@aklaver.com> <1b893a10-1dfd-4abf-b066-9b544c2fa985@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox