3

I am trying to set up replication for PostgreSQL on Ubuntu 20.04 and for the stand-by node I just need to install the PostgreSQL-server and not run initdb. Cluster creation on the stand-by will be taken care of when I will setup replication from master.

But, when ever I am running

sudo apt-get -y install postgresql

initdb is called and cluster is created. In other distribution such as RHEL, it is possible to not run initdb and just install the postgresql server using packages (https://www.postgresql.org/download/linux/redhat/).

Is there any way to get around this? or is this just how installation works on ubuntu when installing using apt-get?

2
  • 1
    That has bothered me as well. Feb 11, 2022 at 8:23
  • 1
    I guess the easiest way is to run pg_dropcluster right after apt-get
    – user1822
    Feb 11, 2022 at 9:09

2 Answers 2

0

IIRC there is no way with apt directly, but you can more manually as in the answer to this question: https://askubuntu.com/a/482936

The process would be:

  1. Install the dependencies
  2. Get and unpack the package with apt-get download <package>; sudo dpkg --unpack <package>*.deb
  3. Edit /var/lib/dpkg/info/<package>.postinst (the linked answer just deletes it, but there may be other tasks you still require it to perform)
  4. Complete the instead with sudo dpkg --configure <package>; sudo apt-get install -yf #To verify/fix dependencies

That final step might be sufficient to allow you to skip installing dependencies beforehand in step 1, if that it the case then there is also the advantage that they'll be automatically removed if you remove pg and nothing else requires them.

A manual approach like this might be fine for a one-off, and personally when upgrades happen the post-install script won't see the need to run something like initdb as things are already configured being the point where that is needed. If you need this a lot, as part of a product install perhaps, then it could be cumbersome, the other options then are to have a script to undo what initdb does after the fact, or maintain your own apt repo containing modified versions of this package (which in itself is a chunk of admin).

0

When installing postgresql-common, it prints among other things:

Creating config file /etc/postgresql-common/createcluster.conf with new version

The first option in that file is:

# Create a "main" cluster when a new postgresql-x.y server package is installed
#create_main_cluster = true

Turning this options to false will make subsequent installations of Postgresql server packages to not auto-create clusters.

If postgresql-common is not already installed when a Postgresql server package is installed, it will be pulled as a dependency, but then there's no time to adjust that create_main_cluster option. So postgresql-common should be installed first, separately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.