Score:1

Is there a way to install PostgreSQL using apt-get without it running initdb automatically?

sr flag

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?

Score:1
in flag

Q: 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

There are two ways to do that:

  1. Either set the following option to off in /etc/postgresql-common/createcluster.conf:

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

    This configuration file is part of the postgresql-common package, which must be installed first to have the opportunity to overwrite this option ( otherwise, it will be installed automatically as a dependency of the postgresql-$VERSION package).

  2. Or create the directory /etc/postgresql/$VERSION before the postgresql-$VERSION package gets installed. The existence of this directory will make the post-installation script skip the creation of a default cluster.

UdIt Solanki avatar
sr flag
This worked as well. Thanks!
Score:1
in flag

Debian-based Linux distributions — such as Ubuntu — will start new services as part of the post-installation scripts when installing via apt. This has been the default behaviour "forever". That said, you can temporarily disable this by temporarily creating a policy-rc.d file.

Here's how:

  1. Open Terminal (or SSH into the machine)
  2. Create a policy-rc.d file in /usr/sbin:
    sudo {editor of choice} /etc/sbin/policy-rc.d
    
    Note: Be sure to replace {editor of choice} with your editor of choice.
  3. Paste the following lines into the new file:
    #!/bin/sh
    exit 101
    
  4. Save the file and exit the editor
  5. Install your application(s)

Once you are done, be sure to remove the policy-rc.d file, otherwise any future apt install operations may not succeed, such as system updates.

UdIt Solanki avatar
sr flag
This worked very well. Thanks!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.