We have already covered the basics of creating a script file and a .control
file. Actually, that is all that is necessary for a PostgreSQL extension. You may simply copy these files into the shared extension directory on your computer and execute the following command:
CREATE EXTENSION postal;
This will install your extension into the currently selected database.
The shared extension path is dependent on how PostgreSQL is installed, but for Ubuntu, it is /usr/share/postgresql/9.2/extension
.
However, there is a much better way to do this that works with any package manager on any platform.
PostgreSQL provides an extension-building toolkit as a part of the server development package. To install this package on Ubuntu, you can type:
sudo apt-get install postgresql-dev-9.4
This will install all of the PostgreSQL source code necessary to create and install an extension. You would then create a file named Makefile
in the same directory as the rest of your extension files. The content of this file looks like this:
EXTENSION = postal DATA = postal--1.0.sql PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS)
This simple Makefile
file will copy your extension script file and the .control
file into the proper shared extension directory on any platform. Invoke it with this command:
sudo make install
You will see some output like this:
/bin/mkdir -p '/usr/share/postgresql/9.4/extension' /bin/sh /usr/lib/postgresql/9.4/lib/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./postal.control '/usr/share/postgresql/9.4/extension/' /bin/sh /usr/lib/postgresql/9.4/lib/pgxs/src/makefiles/../../config/install-sh -c -m 644 ./postal--1.0.sql '/usr/share/postgresql/9.4/extension/'
Your extension is now located in the proper directory for installation. You can install it into the current database with:
CREATE EXTENSION postal;
You will then see the confirmation text letting you know that you have now gone postal:
CREATE EXTENSION
3.137.199.182