Skip to content

Commit 4f7f7b0

Browse files
peteremattheusv
andcommitted
extension_control_path
The new GUC extension_control_path specifies a path to look for extension control files. The default value is $system, which looks in the compiled-in location, as before. The path search uses the same code and works in the same way as dynamic_library_path. Some use cases of this are: (1) testing extensions during package builds, (2) installing extensions outside security-restricted containers like Python.app (on macOS), (3) adding extensions to PostgreSQL running in a Kubernetes environment using operators such as CloudNativePG without having to rebuild the base image for each new extension. There is also a tweak in Makefile.global so that it is possible to install extensions using PGXS into an different directory than the default, using 'make install prefix=/else/where'. This previously only worked when specifying the subdirectories, like 'make install datadir=/else/where/share pkglibdir=/else/where/lib', for purely implementation reasons. (Of course, without the path feature, installing elsewhere was rarely useful.) Author: Peter Eisentraut <peter@eisentraut.org> Co-authored-by: Matheus Alcantara <matheusssilv97@gmail.com> Reviewed-by: David E. Wheeler <david@justatheory.com> Reviewed-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Reviewed-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Reviewed-by: Niccolò Fei <niccolo.fei@enterprisedb.com> Discussion: https://www.postgresql.org/message-id/flat/E7C7BFFB-8857-48D4-A71F-88B359FADCFD@justatheory.com
1 parent 2cce0fe commit 4f7f7b0

File tree

13 files changed

+512
-185
lines changed

13 files changed

+512
-185
lines changed

doc/src/sgml/config.sgml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10954,6 +10954,74 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir'
1095410954
</listitem>
1095510955
</varlistentry>
1095610956

10957+
<varlistentry id="guc-extension-control-path" xreflabel="extension_control_path">
10958+
<term><varname>extension_control_path</varname> (<type>string</type>)
10959+
<indexterm>
10960+
<primary><varname>extension_control_path</varname> configuration parameter</primary>
10961+
</indexterm>
10962+
</term>
10963+
<listitem>
10964+
<para>
10965+
A path to search for extensions, specifically extension control files
10966+
(<filename><replaceable>name</replaceable>.control</filename>). The
10967+
remaining extension script and secondary control files are then loaded
10968+
from the same directory where the primary control file was found.
10969+
See <xref linkend="extend-extensions-files"/> for details.
10970+
</para>
10971+
10972+
<para>
10973+
The value for <varname>extension_control_path</varname> must be a
10974+
list of absolute directory paths separated by colons (or semi-colons
10975+
on Windows). If a list element starts
10976+
with the special string <literal>$system</literal>, the
10977+
compiled-in <productname>PostgreSQL</productname> extension
10978+
directory is substituted for <literal>$system</literal>; this
10979+
is where the extensions provided by the standard
10980+
<productname>PostgreSQL</productname> distribution are installed.
10981+
(Use <literal>pg_config --sharedir</literal> to find out the name of
10982+
this directory.) For example:
10983+
<programlisting>
10984+
extension_control_path = '/usr/local/share/postgresql/extension:/home/my_project/share/extension:$system'
10985+
</programlisting>
10986+
or, in a Windows environment:
10987+
<programlisting>
10988+
extension_control_path = 'C:\tools\postgresql\extension;H:\my_project\share\extension;$system'
10989+
</programlisting>
10990+
Note that the path elements should typically end in
10991+
<literal>extension</literal> if the normal installation layouts are
10992+
followed. (The value for <literal>$system</literal> already includes
10993+
the <literal>extension</literal> suffix.)
10994+
</para>
10995+
10996+
<para>
10997+
The default value for this parameter is
10998+
<literal>'$system'</literal>. If the value is set to an empty
10999+
string, the default <literal>'$system'</literal> is also assumed.
11000+
</para>
11001+
11002+
<para>
11003+
This parameter can be changed at run time by superusers and users
11004+
with the appropriate <literal>SET</literal> privilege, but a
11005+
setting done that way will only persist until the end of the
11006+
client connection, so this method should be reserved for
11007+
development purposes. The recommended way to set this parameter
11008+
is in the <filename>postgresql.conf</filename> configuration
11009+
file.
11010+
</para>
11011+
11012+
<para>
11013+
Note that if you set this parameter to be able to load extensions from
11014+
nonstandard locations, you will most likely also need to set <xref
11015+
linkend="guc-dynamic-library-path"/> to a correspondent location, for
11016+
example,
11017+
<programlisting>
11018+
extension_control_path = '/usr/local/share/postgresql/extension:$system'
11019+
dynamic_library_path = '/usr/local/lib/postgresql:$libdir'
11020+
</programlisting>
11021+
</para>
11022+
</listitem>
11023+
</varlistentry>
11024+
1095711025
<varlistentry id="guc-gin-fuzzy-search-limit" xreflabel="gin_fuzzy_search_limit">
1095811026
<term><varname>gin_fuzzy_search_limit</varname> (<type>integer</type>)
1095911027
<indexterm>

doc/src/sgml/extend.sgml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,11 @@ RETURNS anycompatible AS ...
649649
control file can specify a different directory for the script file(s).
650650
</para>
651651

652+
<para>
653+
Additional locations for extension control files can be configured using
654+
the parameter <xref linkend="guc-extension-control-path"/>.
655+
</para>
656+
652657
<para>
653658
The file format for an extension control file is the same as for the
654659
<filename>postgresql.conf</filename> file, namely a list of
@@ -669,9 +674,9 @@ RETURNS anycompatible AS ...
669674
<para>
670675
The directory containing the extension's <acronym>SQL</acronym> script
671676
file(s). Unless an absolute path is given, the name is relative to
672-
the installation's <literal>SHAREDIR</literal> directory. The
673-
default behavior is equivalent to specifying
674-
<literal>directory = 'extension'</literal>.
677+
the installation's <literal>SHAREDIR</literal> directory. By default,
678+
the script files are looked for in the same directory where the
679+
control file was found.
675680
</para>
676681
</listitem>
677682
</varlistentry>
@@ -719,8 +724,8 @@ RETURNS anycompatible AS ...
719724
<para>
720725
The value of this parameter will be substituted for each occurrence
721726
of <literal>MODULE_PATHNAME</literal> in the script file(s). If it is not
722-
set, no substitution is made. Typically, this is set to
723-
<literal>$libdir/<replaceable>shared_library_name</replaceable></literal> and
727+
set, no substitution is made. Typically, this is set to just
728+
<literal><replaceable>shared_library_name</replaceable></literal> and
724729
then <literal>MODULE_PATHNAME</literal> is used in <command>CREATE
725730
FUNCTION</command> commands for C-language functions, so that the script
726731
files do not need to hard-wire the name of the shared library.
@@ -1804,6 +1809,10 @@ include $(PGXS)
18041809
setting <varname>PG_CONFIG</varname> to point to its
18051810
<command>pg_config</command> program, either within the makefile
18061811
or on the <literal>make</literal> command line.
1812+
You can also select a separate installation directory for your extension
1813+
by setting the <literal>make</literal> variable <varname>prefix</varname>
1814+
on the <literal>make</literal> command line. (But this will then require
1815+
additional setup to get the server to find the extension there.)
18071816
</para>
18081817

18091818
<para>

doc/src/sgml/ref/create_extension.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ CREATE EXTENSION [ IF NOT EXISTS ] <replaceable class="parameter">extension_name
9090
<para>
9191
The name of the extension to be
9292
installed. <productname>PostgreSQL</productname> will create the
93-
extension using details from the file
94-
<literal>SHAREDIR/extension/</literal><replaceable class="parameter">extension_name</replaceable><literal>.control</literal>.
93+
extension using details from the file <filename><replaceable
94+
class="parameter">extension_name</replaceable>.control</filename>,
95+
found via the server's extension control path (set by <xref
96+
linkend="guc-extension-control-path"/>.)
9597
</para>
9698
</listitem>
9799
</varlistentry>

src/Makefile.global.in

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,19 @@ endif # not PGXS
8787
#
8888
# In a PGXS build, we cannot use the values inserted into Makefile.global
8989
# by configure, since the installation tree may have been relocated.
90-
# Instead get the path values from pg_config.
90+
# Instead get the path values from pg_config. But users can specify
91+
# prefix explicitly, if they want to select their own installation
92+
# location.
9193

92-
ifndef PGXS
94+
ifdef PGXS
95+
# Extension makefiles should set PG_CONFIG, but older ones might not
96+
ifndef PG_CONFIG
97+
PG_CONFIG = pg_config
98+
endif
99+
endif
100+
101+
# This means: if ((not PGXS) or prefix)
102+
ifneq (,$(if $(PGXS),,1)$(prefix))
93103

94104
# Note that prefix, exec_prefix, and datarootdir aren't defined in a PGXS build;
95105
# makefiles may only use the derived variables such as bindir.
@@ -147,11 +157,6 @@ localedir := @localedir@
147157

148158
else # PGXS case
149159

150-
# Extension makefiles should set PG_CONFIG, but older ones might not
151-
ifndef PG_CONFIG
152-
PG_CONFIG = pg_config
153-
endif
154-
155160
bindir := $(shell $(PG_CONFIG) --bindir)
156161
datadir := $(shell $(PG_CONFIG) --sharedir)
157162
sysconfdir := $(shell $(PG_CONFIG) --sysconfdir)

0 commit comments

Comments
 (0)