Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">16.3.0</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/containers/current/docs/install-postgis.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/containers/18.4.0/docs/install-postgis.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/install-postgis.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/containers/18.1.0/docs/install-postgis.md.txt)
- [17.10.0](https://docs.cloud.google.com/alloydb/omni/containers/17.10.0/docs/install-postgis.md.txt)
- [17.9.0](https://docs.cloud.google.com/alloydb/omni/containers/17.9.0/docs/install-postgis.md.txt)
- [17.7.0](https://docs.cloud.google.com/alloydb/omni/containers/17.7.0/docs/install-postgis.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/install-postgis.md.txt)
- [16.14.0](https://docs.cloud.google.com/alloydb/omni/containers/16.14.0/docs/install-postgis.md.txt)
- [16.13.0](https://docs.cloud.google.com/alloydb/omni/containers/16.13.0/docs/install-postgis.md.txt)
- [16.11.0](https://docs.cloud.google.com/alloydb/omni/containers/16.11.0/docs/install-postgis.md.txt)
- [16.9.0](https://docs.cloud.google.com/alloydb/omni/containers/16.9.0/docs/install-postgis.md.txt)
- [16.8.0](https://docs.cloud.google.com/alloydb/omni/containers/16.8.0/docs/install-postgis.md.txt)
- [16.3.0](https://docs.cloud.google.com/alloydb/omni/containers/16.3.0/docs/install-postgis.md.txt)
- [15.18.0](https://docs.cloud.google.com/alloydb/omni/containers/15.18.0/docs/install-postgis.md.txt)
- [15.17.0](https://docs.cloud.google.com/alloydb/omni/containers/15.17.0/docs/install-postgis.md.txt)
- [15.15.0](https://docs.cloud.google.com/alloydb/omni/containers/15.15.0/docs/install-postgis.md.txt)
- [15.13.0](https://docs.cloud.google.com/alloydb/omni/containers/15.13.0/docs/install-postgis.md.txt)
- [15.12.0](https://docs.cloud.google.com/alloydb/omni/containers/15.12.0/docs/install-postgis.md.txt)
- [15.7.1](https://docs.cloud.google.com/alloydb/omni/containers/15.7.1/docs/install-postgis.md.txt)
- [15.7.0](https://docs.cloud.google.com/alloydb/omni/containers/15.7.0/docs/install-postgis.md.txt)
- [15.5.5](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/install-postgis.md.txt)
- [15.5.4](https://docs.cloud.google.com/alloydb/omni/containers/15.5.4/docs/install-postgis.md.txt)
- [15.5.2](https://docs.cloud.google.com/alloydb/omni/containers/15.5.2/docs/install-postgis.md.txt)

<br />

<button value="debian" default="">Debian</button> <button value="ubi">UBI</button>

<br />

To store, index, and query geospatial data in AlloyDB Omni, you can
manually add the [PostGIS extension](https://postgis.net/) to your
installation.

You can install PostGIS by using either of the following methods:

- Use Debian options in the Docker or Podman CLI. Docker relies on a daemon and requires root privileges for most operations, while Podman is daemonless and rootless.
- Use Red Hat Universal Base Images (UBI). UBI container base operating system images are built from parts of Red Hat Enterprise Linux (RHEL).

## Before you begin

[Install AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/16.3.0/docs/deploy-vm.md.txt) on your system.

## Add PostGIS to your AlloyDB Omni installation

To add the PostGIS extension to your AlloyDB Omni installation,
follow these steps:

1. Find your installed AlloyDB Omni version labels:

   ### Docker

   ```bash
   docker run --rm -it google/alloydbomni cat VERSION.txt
   ```

   ### Podman

   ```bash
   podman run --rm -it google/alloydbomni cat VERSION.txt
   ```

   The output is similar to the following:

       AlloyDB Omni version: 16.3.0

   Take note of the AlloyDB Omni version number because you need
   it in the next step.
2. Set the `OMNI_VERSION` environment variable:

   ```bash
   OMNI_VERSION=VERSION
   ```

   Replace `VERSION` with the complete
   AlloyDB Omni database server version---for example,
   `16.3.0`.
3. Build a custom Docker image that includes the PostGIS extension:

   ```bash
   mkdir -p ~/alloydb-omni-postgis

   tee ~/alloydb-omni-postgis/Dockerfile << 'EOF'
   ARG OMNI_VERSION
   FROM google/alloydbomni:${OMNI_VERSION}
   RUN apt-get update && \
         apt-get install -y --no-install-recommends \
         postgresql-16-postgis-3 \
         postgresql-16-address-standardizer \
         postgresql-16-postgis-tiger-geocoder && \
         apt-get purge -y --auto-remove && \
         rm -rf /var/lib/apt/lists/*
   EOF

   cd ~/alloydb-omni-postgis

   sudo docker build --build-arg OMNI_VERSION=$OMNI_VERSION \
     --tag google/alloydbomni-with-postgis:$OMNI_VERSION .
   ```
4. Create a container with AlloyDB Omni named `my-omni-postgis`:

   ### Docker

   ```bash
   docker run --name my-omni-postgis \
     -e POSTGRES_PASSWORD=NEW_PASSWORD \
     -d google/alloydbomni-with-postgis:$OMNI_VERSION
   ```

   ### Podman

   ```bash
   podman run --name my-omni-postgis \
     -e POSTGRES_PASSWORD=NEW_PASSWORD \
     -d google/alloydbomni-with-postgis:$OMNI_VERSION
   ```

   Replace `NEW_PASSWORD` with a password for the default
   `postgres` user.
5. Connect to your database with the PostGIS extension:

   ```bash
   docker exec -it my-omni-postgis psql -h localhost -U postgres
   ```
6. Enable PostGIS:

   ```sql
   CREATE EXTENSION IF NOT EXISTS POSTGIS;
   SELECT postgis_full_version();
   ```

   The output is similar to the following:

       postgis_full_version
       ---
       POSTGIS="3.3.2 4975da8" [EXTENSION] PGSQL="150" GEOS="3.11.1-CAPI-1.17.1" PROJ="9.1.1" LIBXML="2.9.14" LIBJSON="0.16" LIBPROTOBUF="1.4.1" WAGYU="0.5.0 (Internal)"
       (1 row)