pg_buildext - Man Page

Build and install a PostgreSQL extension


pg_buildext [options] action [src-dir] [arguments]


pg_buildext is a script that will build a PostgreSQL extension in a VPATH way, for potentially several PostgreSQL server versions in parallel. It builds for the intersection of versions known in debian/pgversions (versions supported by the package) and in /usr/share/postgresql-common/supported-versions (versions supported in this release).


Packages using pg_buildext should be prepared to build binaries for PostgreSQL versions that are not present in Debian unstable, e.g. for older releases when building backports for Debian (old)stable (possibly including backports of newer PostgreSQL releases), or for all PostgreSQL releases when the package is built for

As the set of binary packages depends on the target PostgreSQL versions, debian/control is generated from a template in debian/ when pg_buildext updatecontrol is run. Occurrences of PGVERSION in package sections are replaced by the target PostgreSQL version. Include /usr/share/postgresql-common/ in debian/rules to run a check at build time if updating debian/control is required.

As pg_buildext invokes make for the build, install, and clean actions, invocations from debian/rules (which is a makefile) should be prefixed with + so the sub-makes can talk with the make jobserver.

Many extensions support make installcheck testing using pg_regress. As this needs the package to be installed, it cannot be run at build time. Instead, the tests should be run using autopkgtest from debian/tests/*.

If debian/tests/ exists, occurrences of package names containing PGVERSION are replaced by lists of package names with the target PostgreSQL versions filled in. (If no replacing is needed in debian/tests/control, it is fine to provide the tests control file directly.)


-cio arg

Passed to pg_virtualenv when running installcheck.


Most actions expect a directory name where to build the sources. It will get created for you if it does not exist. If the build-dir contains a %v sign, it will get replaced by the specific version of PostgreSQL being built against. (Usually this parameter is build-%v.)


Print effective list of supported versions, i.e. the intersection of the sets of versions supported by the system and the package.


Check if debian/control needs updating from debian/ This is invoked from /usr/share/postgresql-common/ When building for a backports or pgdg suite as determined by debian/changelog, this action also updates the control file. Otherwise, updatecontrol needs to be run manually.


Update debian/control from debian/, and debian/tests/control from debian/tests/ if the latter exists.

configure [src-dir] build-dir [extra-configure-options]

For every supported version, call ../configure from the build-dir directory. (Most PostgreSQL extensions do not have a configure script.)

build [src-dir] build-dir [extra-cflags]

Build the extension in the build-dir directory.

install [src-dir] build-dir package-pattern

Invoke make install from the build-dir directory. The third parameter specifies the package name to use. Most packages use postgresql-%v-pkgname. Make will be called with DESTDIR="$(CURDIR)/debian/package".

clean [src-dir] build-dir

Clean the build directory.

loop [src-dir] package-pattern

As a variant to calling build and install separately for VPATH builds, loop over the supported PostgreSQL versions in the top source directory. This should be used if the package does not support VPATH builds. As it also invokes make install, it should be placed were installation happens in debian/rules, rather than where build would normally be called.

installcheck [src-dir] [build-dir]

Use pg_virtualenv make installcheck to run the extension regression tests. This is meant to be run from debian/tests/control using autopkgtest. If build-dir is omitted, the top source directory is used.

Sometimes it is desirable to run extra code per version before invoking the action, in that case the loop over supported versions needs to be in the calling script. To facilitate this mode, actions can also be called as action-version. See the installcheck example below.

Supported Versions

pg_buildext reads debian/pgversions to decide which PostgreSQL to build modules/extensions for. This file contains one PostgreSQL version number per line, in the following formats:


Support all versions. This is recommended unless there are known incompatibilities.


Support this version.


Support this and all greater versions.



For a version to be used, it must also be listed in the output of /usr/share/postgresql-common/supported-versions. See this file for how to configure the list of supported versions on your system.


  Source: postgresql-foobar
  Build-Depends: debhelper, postgresql-server-dev-all (>= 153~)
  XS-Testsuite: autopkgtest

  Package: postgresql-PGVERSION-foobar
  Depends: ${misc:Depends}, ${shlibs:Depends}, postgresql-PGVERSION
  #!/usr/bin/make -f

  include /usr/share/postgresql-common/

  # omit this if the package does not use autoconf
          +pg_buildext configure build-%v "--libdir=/usr/lib/postgresql/%v/lib --datadir=/usr/share/postgresql-%v-foobar"

          +pg_buildext build build-%v

          # nothing to do here, see debian/tests/* instead

          +pg_buildext install build-%v postgresql-%v-foobar

          dh_installdocs --all README.*

          +pg_buildext clean build-%v

          dh $@
  Depends: @, postgresql-server-dev-all
  Tests: installcheck
  Restrictions: allow-stderr
debian/tests/ (optional)
  Depends: @, postgresql-contrib-PGVERSION, postgresql-PGVERSION-bar
  Tests: installcheck
  Restrictions: allow-stderr
  pg_buildext installcheck
  # alternatively: pg_buildext installcheck build-%v

  # Running extra code before invoking the actual action:
  set -e
  for v in $(pg_buildext supported-versions); do
          test -L build-$v/sql || ln -s ../sql build-$v/
          test -L build-$v/expected || ln -s ../expected build-$v/
          pg_buildext installcheck-$v build-$v

Source Directory

If the package source code is not in the top level directory (i.e. the directory which has debian/ as subdirectory), use the src-dir argument. Example:

          +pg_buildext build $(CURDIR)/postgresql-module build-%v


pg_buildext loop was introduced in postgresql-server-dev-all (>= 141~).

The usage of “all” or “X.Y+” in debian/pgversions was introduced in postgresql-server-dev-all (>= 148~).

pg_buildext installcheck was introduced in postgresql-server-dev-all (>= 153~).

PG_VIRTUALENV_UNSHARE=-n was introduced in postgresql-common (>= 170~).

Handling of debian/tests/ with PGVERSION replacement was introduced in postgresql-common (>= 171~).

See Also

/usr/share/postgresql-common/supported-versions, autopkgtest(1), pg_virtualenv(1).


Dimitri Fontaine <>, with extensions by Christoph Berg <>.


2018-09-26 Debian PostgreSQL infrastructure