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

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/linux/current/docs/install-postgis.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/linux/18.4.0/docs/install-postgis.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/linux/18.3.0/docs/install-postgis.md.txt)
- [18.1.1](https://docs.cloud.google.com/alloydb/omni/linux/18.1.1/docs/install-postgis.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/linux/18.1.0/docs/install-postgis.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/linux/17.5.0/docs/install-postgis.md.txt)

<br />

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

## Before you begin

[Install AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/linux/18.1.1/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. Initialize Red Hat Subscription Manager on the VM where you installed the
   AlloyDB Omni server:

   ```bash
   sudo dnf install -y subscription-manager
   sudo subscription-manager register \
     --username "RHSM_USER" \
     --password "RHSM_PASS" \
     --auto-attach --force
   ```

   Replace the following:
   - `RHSM_USER`: the Red Hat Subscription Manager user.
   - `RHSM_PASS`: the Red Hat Subscription Manager password.
2. Enable the CodeReady Builder repository:

   ```bash
   sudo subscription-manager repos \
     --enable="codeready-builder-for-rhel-9-ARCH-rpms"
   ```

   Replace `ARCH` with the RHEL architecture that you
   want to use---for example, `x86_64`.
3. Add the PostgreSQL Yum repository:

   ```bash
   sudo dnf install -y \
     https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-ARCH/pgdg-redhat-repo-latest.noarch.rpm
   ```

   Replace `ARCH` with the RHEL architecture that you
   want to use---for example, `x86_64`.
4. Install the PostGIS extension:

   ```bash
   sudo dnf install -y postgis35_18
   ```
5. Create the required symbolic links so that the extensions are in the expected
   paths:

   ```bash
   set -e
   PGVER="18"

   sudo mkdir -p "/usr/lib/postgresql/${PGVER}/share/extension"

   for file in /usr/pgsql-${PGVER}/share/extension/*; do
       target="/usr/lib/postgresql/${PGVER}/share/extension/$(basename "$file")"
       if [[ ! -e "$target" ]]; then
         sudo ln -s "$file" "$target" || (echo "Failed to link \"$file\" to \"$target\", exiting." && exit 1)
         echo "Created extension link for $(basename "$file")"
       else
         echo "Target $target already exists."
       fi
   done

   sudo mkdir -p "/usr/lib/postgresql/${PGVER}/lib"

   for file in /usr/pgsql-${PGVER}/lib/*; do
       target="/usr/lib/postgresql/${PGVER}/lib/$(basename "$file")"
       if [[ ! -e "$target" ]]; then
         sudo ln -s "$file" "$target" || (echo "Failed to link \"$file\" to \"$target\", exiting." && exit 1)
         echo "Created lib link for $(basename "$file")"
       else
         echo "Target $target already exists."
       fi
   done
   ```
6. Connect to your database and run the `CREATE EXTENSION` command to enable
   PostGIS:


   For instructions on connecting to your instance, see
   [Run and connect to AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/linux/18.1.1/docs/run-connect.md.txt).

   ```sql
   CREATE EXTENSION IF NOT EXISTS POSTGIS;
   ```
7. Confirm that PostGIS is installed and enabled:

   ```sql
   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.18.1" PROJ="9.1.1" LIBXML="2.9.14" LIBJSON="0.16" LIBPROTOBUF="1.4.1" WAGYU="0.5.0 (Internal)"
       (1 row)