36.18. Extension Building Infrastructure#
If you are thinking about distributing yourPostgres Pro extension modules, setting up a portable build system for them can be fairly difficult. Therefore thePostgres Pro installation provides a build infrastructure for extensions, calledPGXS, so that simple extension modules can be built simply against an already installed server.PGXS is mainly intended for extensions that include C code, although it can be used for pure-SQL extensions too. Note thatPGXS is not intended to be a universal build system framework that can be used to build any software interfacing toPostgres Pro; it simply automates common build rules for simple server extension modules. For more complicated packages, you might need to write your own build system. To use thePGXS infrastructure for your extension, you must write a simple makefile. In the makefile, you need to set some variables and include the globalPGXS makefile. Here is an example that builds an extension module named The last three lines should always be the same. Earlier in the file, you assign variables or add custommake rules. Set one of these three variables to specify what is built: The following variables can also be set: extension name(s); for each name you must provide an subdirectory of random files to install into random files to install into random files to install under random files to install under Files to (optionally build and) install under Unlike Files to install (after building if specified) under Unlike It is legal to use both variables for the same module, or any combination, unless you have two module names in the script files (not binaries) to install into script files (not binaries) to install into list of regression test cases (without suffix), see below additional switches to pass topg_regress list of isolation test cases, see below for more details additional switches to pass topg_isolation_regress switch defining if TAP tests need to be run, see below don't define an don't define an extra files to remove in will be prepended to will be appended to will be appended to will be prepended to will be added to will be added to path topg_config program for thePostgres Pro installation to build against (typically just Put this makefile as You can also run Alternatively, you can set up a directory for a VPATH build in a similar way to how it is done for the core code. One way to do this is using the core script This procedure can work with a greater variety of directory layouts. The scripts listed in the The scripts listed in the The easiest way to create the expected files is to create empty files, then do a test run (which will of course report differences). Inspect the actual result files found in theisbn_issn
, consisting of a shared library containing some C code, an extension control file, an SQL script, an include file (only needed if other modules might need to access the extension functions without going via SQL), and a documentation text file:MODULES = isbn_issnEXTENSION = isbn_issnDATA = isbn_issn--1.0.sqlDOCS = README.isbn_issnHEADERS_isbn_issn = isbn_issn.hPG_CONFIG = pg_configPGXS := $(shell $(PG_CONFIG) --pgxs)include $(PGXS)
EXTENSION
#
file, which will be installed intoextension
.controlprefix
/share/extensionMODULEDIR
#
into which DATA and DOCS files should be installed (if not set, default isprefix
/shareextension
ifEXTENSION
is set, orcontrib
if not)DATA
#prefix
/share/$MODULEDIRDATA_built
#
, which need to be built firstprefix
/share/$MODULEDIRDATA_TSEARCH
#prefix
/share/tsearch_dataDOCS
#prefix
/doc/$MODULEDIRHEADERS
HEADERS_built
#
.prefix
/include/server/$MODULEDIR/$MODULE_bigDATA_built
, files inHEADERS_built
are not removed by theclean
target; if you want them removed, also add them toEXTRA_CLEAN
or add your own rules to do it.HEADERS_$MODULE
HEADERS_built_$MODULE
#
, whereprefix
/include/server/$MODULEDIR/$MODULE$MODULE
must be a module name used inMODULES
orMODULE_big
.DATA_built
, files inHEADERS_built_$MODULE
are not removed by theclean
target; if you want them removed, also add them toEXTRA_CLEAN
or add your own rules to do it.MODULES
list that differ only by the presence of a prefixbuilt_
, which would cause ambiguity. In that (hopefully unlikely) case, you should use only theHEADERS_built_$MODULE
variables.SCRIPTS
#prefix
/binSCRIPTS_built
#
, which need to be built firstprefix
/binREGRESS
#REGRESS_OPTS
#ISOLATION
#ISOLATION_OPTS
#TAP_TESTS
#NO_INSTALL
#install
target, useful for test modules that don't need their build products to be installedNO_INSTALLCHECK
#installcheck
target, useful e.g., if tests require special configuration, or don't usepg_regressEXTRA_CLEAN
#make clean
PG_CPPFLAGS
#CPPFLAGS
PG_CFLAGS
#CFLAGS
PG_CXXFLAGS
#CXXFLAGS
PG_LDFLAGS
#LDFLAGS
PG_LIBS
#PROGRAM
link lineSHLIB_LINK
#MODULE_big
link linePG_CONFIG
#pg_config
to use the first one in yourPATH
)Makefile
in the directory which holds your extension. Then you can domake
to compile, and thenmake install
to install your module. By default, the extension is compiled and installed for thePostgres Pro installation that corresponds to the firstpg_config
program found in yourPATH
. You can use a different installation by settingPG_CONFIG
to point to itspg_config
program, either within the makefile or on themake
command line.make
in a directory outside the source tree of your extension, if you want to keep the build directory separate. This procedure is also called aVPATH build. Here's how:mkdir build_dircd build_dirmake -f /path/to/extension/source/tree/Makefilemake -f /path/to/extension/source/tree/Makefile install
config/prep_buildtree
. Once this has been done you can build by setting themake
variableVPATH
like this:make VPATH=/path/to/extension/source/treemake VPATH=/path/to/extension/source/tree install
REGRESS
variable are used for regression testing of your module, which can be invoked bymake installcheck
after doingmake install
. For this to work you must have a runningPostgres Pro server. The script files listed inREGRESS
must appear in a subdirectory namedsql/
in your extension's directory. These files must have extension.sql
, which must not be included in theREGRESS
list in the makefile. For each test there should also be a file containing the expected output in a subdirectory namedexpected/
, with the same stem and extension.out
.make installcheck
executes each test script withpsql, and compares the resulting output to the matching expected file. Any differences will be written to the fileregression.diffs
indiff -c
format. Note that trying to run a test that is missing its expected file will be reported as“trouble”, so make sure you have all expected files.ISOLATION
variable are used for tests stressing behavior of concurrent session with your module, which can be invoked bymake installcheck
after doingmake install
. For this to work you must have a runningPostgres Pro server. The script files listed inISOLATION
must appear in a subdirectory namedspecs/
in your extension's directory. These files must have extension.spec
, which must not be included in theISOLATION
list in the makefile. For each test there should also be a file containing the expected output in a subdirectory namedexpected/
, with the same stem and extension.out
.make installcheck
executes each test script, and compares the resulting output to the matching expected file. Any differences will be written to the fileoutput_iso/regression.diffs
indiff -c
format. Note that trying to run a test that is missing its expected file will be reported as“trouble”, so make sure you have all expected files.TAP_TESTS
enables the use of TAP tests. Data from each run is present in a subdirectory namedtmp_check/
.Tip
results/
directory (for tests inREGRESS
), oroutput_iso/results/
directory (for tests inISOLATION
), then copy them toexpected/
if they match what you expect from the test.