PostGIS is a very popular open source extension for PostgreSQL that introduces support for storing GIS (Geographic Information Systems) objects in the database and be queried via SQL.
This section assumes you are familiar with PostGIS and provides some basic information about how to create a new PostgreSQL cluster with a PostGIS database in Kubernetes via EDB Postgres for Kubernetes.
The CloudNativePG Community maintains container images that are built on top of the official PostGIS images hosted on DockerHub. For more information please visit:
Additionally, EDB provides container images for EDB Postgres Advanced Server
that include PostGIS and makes them available in the official
registry on Quay.io
Conceptually, a PostGIS-based PostgreSQL cluster (or simply a PostGIS cluster) is like any other PostgreSQL cluster. The only differences are:
- the presence in the system of PostGIS and related libraries
- the presence in the database(s) of the PostGIS extension
Since EDB Postgres for Kubernetes is based on Immutable Application Containers, the only way to provision PostGIS is to add it to the container image that you use for the operand. The "Container Image Requirements" section provides detailed instructions on how this is achieved. More simply, you can just use the PostGIS container images from the Community, as in the examples below.
The second step is to install the extension in the PostgreSQL database. You can do this in two ways:
- install it in the application database, which is the main and supposedly only database you host in the cluster according to the microservice architecture, or
- install it in the
template1database so as to make it available for all the databases you end up creating in the cluster, in case you adopt the monolith architecture where the instance is shared by multiple databases
For more information on the microservice vs monolith architecture in the database please refer to the "How many databases should be hosted in a single PostgreSQL instance?" FAQ or the "Database import" section.
Let's suppose you want to create a new PostgreSQL 14 cluster with PostGIS 3.2.
The first step is to ensure you use the right PostGIS container image for the
operand, and properly set the
.spec.imageName option in the
postgis-example.yaml manifest below
provides some guidance on how the creation of a PostGIS cluster can be done.
Please consider that, although convention over configuration applies in
EDB Postgres for Kubernetes, you should spend time configuring and tuning your system for
production. Also the
imageName in the example below deliberately points
to the latest available image for PostgreSQL 14 - you should use a specific
image name or, preferably, the SHA256 digest for true immutability.
The example relies on the
postInitTemplateSQL option which executes a list of
queries against the
template1 database, before the actual creation of the
application database (called
app). This means that, once you have applied the
manifest and the cluster is up, you will have the above extensions installed in
both the template database and the application database, ready for use.
Take some time and look at the available options in
from the API reference, such as
You can easily verify the available version of PostGIS that is in the
container, by connecting to the
app database (you might obtain different
values from the ones in this document):
The next step is to verify that the extensions listed in the
postInitTemplateSQL section have been correctly installed in the