Using PostgreSQL from another source when Percona PostgreSQL repo is enabled

When I’m trying to use the postgresql-14 package from the Ubuntu Jammy OS repo, the postinst for the postgresql-14 package fails with the following error:

/var/lib/dpkg/info/postgresql-14.postinst: 104: db_stop: not found
dpkg: error processing package postgresql-14 (--configure):
 installed postgresql-14 package post-installation script subprocess returned error exit status 127

That postinst script is simple:


set -e


if [ "$1" = configure ]; then
    . /usr/share/postgresql-common/maintscripts-functions

    configure_version $VERSION "$2"

db_stop is from /usr/share/debconf/confmodule… I’ve figured out that that does not get loaded, due to /usr/share/postgresql-common/maintscripts-functions containing this at the bottom: (where it should be sourcing that file)

# start debconf if we are in the server's postinst (can't run from a function)
if [ "${DPKG_MAINTSCRIPT_NAME:-}" = "postinst" ] && [ "$1" = "configure" ]; then
            . /usr/share/debconf/confmodule

That matches the one from the Debian package, after this Percona patch has been applied.

I’ve managed to track down the reason for that - apt prefers installing percona-postgresql-common when attempting to install postgresql-common: (this is with the PGDG repo disabled)

# apt-cache policy postgresql-common
  Installed: 1:241-6.jammy
  Candidate: 1:241-6.jammy
  Version table:
 *** 1:241-6.jammy 500
        500 jammy/main amd64 Packages
        100 /var/lib/dpkg/status
     1:241-5.jammy 500
        500 jammy/main amd64 Packages
     1:241-4.jammy 500
        500 jammy/main amd64 Packages
     1:241-3.jammy 500
        500 jammy/main amd64 Packages
     238 500
        500 jammy/main amd64 Packages

apt-show on that also shows the Percona package instead:

# apt show postgresql-common
Package: postgresql-common
Version: 1:241-6.jammy
Priority: optional
Section: database
Source: percona-postgresql-common
Maintainer: Percona Development Team <>
Installed-Size: 642 kB
Provides: percona-postgresql-common, postgresql-common
Depends: adduser, debconf (>= 0.5.00) | debconf-2.0, libjson-perl, lsb-base (>= 3.0-3), perl (>= 5.14), percona-postgresql-client-common | postgresql-client-common, ssl-cert (>= 1.0.11), ucf
Recommends: e2fsprogs, logrotate
Conflicts: postgresql-common
Breaks: percona-postgresql-server-dev-all (<< 204), postgresql-9.1 (<< 9.1.1-3~), postgresql-server-dev-all (<< 204), systemd (<< 204)
Replaces: percona-postgresql-server-dev-all (<< 204), postgresql-common, postgresql-server-dev-all (<< 204)
Download-Size: 188 kB
APT-Manual-Installed: no
APT-Sources: jammy/main amd64 Packages
<description removed>

I suspect (but can’t easily confirm) that the cause for this is that it is marked that it replaces the postgresql-common package, which might result in percona-postgresql-common being selected instead of the postgresql-common from the other source. (The (PGDG) repos have the same issue)

For this some package pinning works.

For the postgres-15 stuff from PGDG: /etc/apt/preferences.d/postgresql

Package: postgresql-15
Pin: release
Pin-Priority: 550

Package: postgresql-common
Pin: release
Pin-Priority: 550

Package: postgresql-client-common
Pin: release
Pin-Priority: 550

For the OS packages use release o=Ubuntu instead.