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



  • 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?



  • 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 ; sudo dpkg --unpack *.deb
    3. Edit /var/lib/dpkg/info/.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 ; 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).




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2