Subject: AW: PGDG PostgreSQL Debian package: Question on conditions for creation of new cluster

From: Schmid Andreas <[email-masked]>
Date: Wed, 19 Feb 2025 13:22:22 +0000

> -----Ursprüngliche Nachricht-----
> On Wed, 2025-02-19 at 08:45 +0000, Schmid Andreas wrote:
> > I'm trying to install the postgresql-17 Debian package from PGDG apt
> > repo alongside an already existing PostgreSQL 16 installation. So
> > there is already a PostgreSQL 16 cluster on my machine (which I want
> > to upgrade to version 17 using the pg_upgrade command later on).
> >
> > If I'm not wrong, the PostgreSQL packages used to automatically create
> > a new cluster during installation, even if there already was an older
> > cluster present. (Using a different port in this case.) But this
> > doesn't happen with the 17.3 package. Does anyone know if this
> > behavior has changed? Or anyone can explain on which conditions a new
> > cluster is created and when not?
> >
> > There was a now closed discussion on this topic on Stack Overflow:
> > https://stackoverflow.com/questions/79441161/postgres-17-3-installatio
> > n-no-longer-creates-a-new-cluster Of course, I will create the
> > additional cluster using pg_createcluster if this is the way to go.
> > The point is that I'm installing PostgreSQL using an Ansible script,
> > and pg_createcluster was not needed until now.
> > So before I update my script, I hope to get some more information
> > about the behavior of the PostgreSQL packages regarding automatic cluster
> creation.
> 
> I just tried on an Ubuntu system (I think that the packages are pretty much
> the same), and installing 17.3 created a cluster.
> I think the Stackoverflow question was about installing 17.3 if v17 is already
> installed.  In that case, no new cluster is created.
> 

Well, according to the last comment below the Stack Overflow question, it was about installing 17.3 with a v14 cluster already present.
Anyways, I now tried on an Ubuntu 24.04 machine as well, and installing 17.3 alone created a cluster.
Cleaned up the machine, then installed 15.11, which created a cluster. Installed 16.7 alongside, which did not create an additional cluster. So it's probably not a 17.3 problem.
Same outcome on Ubuntu 20.04.

Maybe there generally is no cluster created if there is one present already. I now checked /usr/share/postgresql-common/maintscripts-functions which is installed by the postgresql-common_273.pgdg24.04+1_all.deb package. This script contains the create_main_cluster() function, which according to a comment "skips if any other cluster already exists". 
So could it be that this function has been updated recently? Can you point me to the repo where this script is maintained?

---

From: Laurenz Albe <[email-masked]>
Date: Wed, 19 Feb 2025 16:05:16 +0100

You should ask on the pgsql-pkg-debian mailing list, that's where
the packager is listening.

Yours,
Laurenz Albe

-- 

*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den 
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat 
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte, 
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder 
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich 
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.

*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are 
confidential and may be privileged or otherwise protected from disclosure 
and solely for the use of the person(s) or entity to whom it is intended. 
If you have received this message in error and are not the intended 
recipient, please notify the sender immediately and delete this message and 
any attachment from your system. If you are not the intended recipient, be 
advised that any use of this message is prohibited and may be unlawful, and 
you must not copy this message or attachment or disclose the contents to 
any other person.

---

From: Álvaro Herrera <[email-masked]>
Date: Wed, 19 Feb 2025 16:18:17 +0100

On 2025-Feb-19, Schmid Andreas wrote:

> Maybe there generally is no cluster created if there is one present
> already. I now checked
> /usr/share/postgresql-common/maintscripts-functions which is installed
> by the postgresql-common_273.pgdg24.04+1_all.deb package. This script
> contains the create_main_cluster() function, which according to a
> comment "skips if any other cluster already exists". 
> So could it be that this function has been updated recently? Can you
> point me to the repo where this script is maintained? 

I think that lives here:
https://salsa.debian.org/postgresql/postgresql-common

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"The Postgresql hackers have what I call a "NASA space shot" mentality.
 Quite refreshing in a world of "weekend drag racer" developers."
(Scott Marlowe)

---

From: Adrian Klaver <[email-masked]>
Date: Wed, 19 Feb 2025 08:11:37 -0800

> Same outcome on Ubuntu 20.04.

Which was explained to you in the comments to the SO question. There is 
no 'Installed 16.7 alongside ...'. As was explained this is just minor 
version upgrade to Postgres 16 and will only upgrade the binaries and 
associated libraries for the major version 16.

> So could it be that this function has been updated recently? Can you point me to the repo where this script is maintained?

Do man pg_createcluster.

-- 
Adrian Klaver
[email-masked]

---

From: Schmid Andreas <[email-masked]>
Date: Mon, 24 Feb 2025 13:57:07 +0000

> https://salsa.debian.org/postgresql/postgresql-common

Yes, thanks for the hint. The commit which apparently introduced the change is https://salsa.debian.org/postgresql/postgresql-common/-/commit/d9139f7777a42a39b5b6fabbffc9f020fad4dce5: "debian/maintscripts-functions: Create "main" cluster only when no other clusters exist yet."

Maybe I'm going to ask on the pgsql-pkg-debian mailing list for more details about it, as proposed by Laurenz.

@Adrian, please note that I'm not the one who asked on Stack Overflow, so I'm not cross posting over here. And I definitely am doing an "alongside" installation of two major versions: On my server is installed v16, and now I'm adding v17, as described in my first message.

Thanks again to everybody for your help.

Andy

---

From: Adrian Klaver <[email-masked]>
Date: Mon, 24 Feb 2025 09:12:07 -0800

> @Adrian, please note that I'm not the one who asked on Stack Overflow, so I'm not cross posting over here. And I definitely am doing an "alongside" installation of two major versions: On my server…

So that is what the postgresql-common new packages contained. I have not 
used them for installing a new server version since the changes. Yes 
they indeed do not create a new cluster when any other Postgres clusters 
of any flavor exist. You have to resort to manually doing:

sudo pg_createcluster 17 main --start

It would have been nice if the packagers had mentioned that change 
somewhere else then as comments in the source.