Packaging PostgreSQL extensions in Debian/Ubuntu Systems
/ 5 min read
Hi everyone,
PostgreSQL has a great extensibility in features using extensions. Any feature that a user needs which isnt there natively can be added using extensions. to distribute extensions on different systems, packaging becomes important.
This blog lists down the steps to package a PostgreSQL extension in debian/ubuntu systems. I would be packaging a simple base36 extension to list down the steps.
1. Adding the sources list
To install postgresql packages in debian, the apt.postgresql.org apt list needs to be added.
Run apt install to update the apt list repositry and be able to search for packages using apt command.
2. Setting up the directory
Get your extension source code in a directory. Next from the root of the extension directory, call dh_make_pgxs to setup the boilerplate for the debian folder.
Post this a debian folder would be created. It has same structure of what dh_make creates hence the meaning of the files can be found anywhere on the internet.
3. Updating necessary files
After updating the nexecassry parts, the folder is ready to be built(incase of procedural languages) and packaged.
4. Build the extension
PostgreSQL has a cli tool pg_buildext which is extremely helpful in building the package. A great documentation of it is available on the manpage .
5. Package the extension
The final step comes to packaging the extension. To just verify there must be a README.* file in the root of the extension.
Run the dpkg_buildpackage if a tarball of the source code already exists and dpkg_buildpackage -b if not. This would test the extension on the supported pg versions and then create the necessary deb files ready to be shipped.
After this the parent of the root directory would have deb of each version of the extension would be created.
Gotchas:
The name of the folder of the source code of the extension should be of the form <extension_name>_.
The debian/pgversions file should have a newline otherwise any pg_buildext would neither return any output or any error(status code 0).
The postgresql-all package would be needed to build, install and test the extension on all the supported versions of PostgreSQL.