Installer PostGIS pour AlloyDB Omni

Sélectionnez une version de la documentation :

Cette page explique comment ajouter manuellement l'extension PostGIS à une installation AlloyDB Omni existante. L'extension PostGIS permet de stocker, d'indexer et d'interroger des données géospatiales.

Vous pouvez installer PostGIS à l'aide de l'une des méthodes suivantes :

  • Utilisez les options Debian dans la CLI Docker ou Podman. Docker s'appuie sur un daemon et nécessite des droits racine pour la plupart des opérations, tandis que Podman est sans daemon et sans racine.
  • Utilisez les images de base universelles (UBI) Red Hat. Les images de système d'exploitation de base de conteneur UBI sont créées à partir de composants de Red Hat Enterprise Linux (RHEL).

Avant de commencer

Installez AlloyDB Omni sur votre système.

Ajouter PostGIS à votre installation AlloyDB Omni

Pour ajouter l'extension PostGIS à votre installation AlloyDB Omni, procédez comme suit :

  1. Recherchez les libellés de la version d'AlloyDB Omni installée :

    Docker

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

    Podman

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

    Le résultat ressemble à ce qui suit :

    AlloyDB Omni version: 16.8.0
    

    Notez le numéro de version d'AlloyDB Omni, car vous en aurez besoin à l'étape suivante.

  2. Définissez la variable d'environnement OMNI_VERSION :

    OMNI_VERSION=VERSION
    

    Remplacez VERSION par la version complète du serveur de base de données de l'étape précédente, par exemple 16.8.0.

  3. Créez une image Docker personnalisée incluant l'extension PostGIS :

    mkdir ~/alloydb-omni-postgis
    
    cd ~/alloydb-omni-postgis
    
    sudo dnf install -y subscription-manager
    
    sudo subscription-manager register --username EMAIL --password PASSWORD --auto-attach
    
    sudo mkdir -p entitlement rhsm-conf rhsm-ca
        sudo cp -r /etc/pki/entitlement/* entitlement/
        sudo cp -r /etc/rhsm/rhsm.conf rhsm-conf/
        sudo cp -r /etc/rhsm/ca/* rhsm-ca/
    
    cat <<EOF > Dockerfile
        FROM google/alloydbomni:16.8.0-ubi
        COPY ./entitlement /etc/pki/entitlement
        COPY ./rhsm-conf /etc/rhsm
        COPY ./rhsm-ca /etc/rhsm/ca
        RUN arch=$(uname -m) && \
            subscription-manager repos --enable codeready-builder-for-rhel-9-${arch}-rpms && \
            dnf install -y \
            https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-${arch}/pgdg-redhat-repo-latest.noarch.rpm && \
            dnf install -y postgresql16-server postgis34_16 && \
            dnf clean all
        # On RHEL-based systems, PostgreSQL extensions like Orafce and PostGIS are typically installed in /usr/pgsql-16/share/extension and /usr/pgsql-16/lib.
        # This step creates symbolic links to those files in the paths expected by AlloyDB Omni,
        # which lets AlloyDB Omni locate extension control files and shared libraries without duplicating data.
        RUN for file in /usr/pgsql-16/share/extension/*; do \
           target="/usr/lib/postgresql/16/share/extension/$(realpath -m --relative-to=/usr/pgsql-16/share/extension/ "$file")"; \
           if [ ! -e "$target" ]; then \
              ln -s "$file" "$target" || (echo "Failed to link \"$file\" to \"$target\", exiting." && exit 1); \
           else \
              echo "$target already exists"; \
           fi; \
        done && \
        for file in /usr/pgsql-16/lib/*; do \
           target="/usr/lib/postgresql/16/lib/$(realpath -m --relative-to=/usr/pgsql-16/lib/ "$file")"; \
           if [ ! -e "$target" ]; then \
              ln -s "$file" "$target" || (echo "Failed to link \"$file\" to \"$target\", exiting." && exit 1); \
           else \
              echo "$target already exists"; \
           fi; \
        done
    EOF
    

  4. Créez un conteneur avec AlloyDB Omni nommé my-omni-postgis :

    Docker

    docker build -t google/alloydbomni-with-postgis:latest
    docker run --name my-omni-postgis  -e POSTGRES_PASSWORD=NEW_PASSWORD  -d google/alloydbomni-with-postgis:OMNI_VERSION
    

    Podman

    podman run --name my-omni-postgis  -e POSTGRES_PASSWORD=NEW_PASSWORD  -d google/alloydbomni-with-postgis:OMNI_VERSION
    
  5. Connectez-vous à votre base de données avec l'extension PostGIS :

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

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

    La sortie ressemble à ceci :

    postgres=# SELECT postgis_full_version();
    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)