AlloyDB Omni 用に PostGIS をインストールする

AlloyDB Omni には PostGIS 拡張機能は含まれていませんが、このページの手順に沿って既存の AlloyDB Omni インストールに手動で追加し、地理空間データの保存、インデックス作成、クエリのサポートを追加できます。

始める前に

システムに AlloyDB Omni がインストールされていることを確認します。

AlloyDB Omni インストールに PostGIS を追加する

AlloyDB Omni インストールに PostGIS 拡張機能を追加する手順は次のとおりです。

  1. インストールされている AlloyDB Omni バージョンのラベルを確認します。

    Docker

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

    Podman

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

    出力は次のようになります。

    AlloyDB Omni version: 15.7.0
    

    AlloyDB Omni のバージョン番号をメモします。これは次のステップで必要になります。

  2. OMNI_VERSION 環境変数を設定します。
    OMNI_VERSION=VERSION

    VERSION は、前の手順で確認したデータベース サーバーの完全なバージョンに置き換えます(例: 15.7.0)。

  3. PostGIS を含む新しい AlloyDB Omni コンテナを作成します。

    Linux

           mkdir ~/alloydb-omni-postgis
           tee -a ~/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-15-postgis-3 &&
    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 .

    macOS

           mkdir ~/alloydb-omni-postgis
           tee -a ~/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-15-postgis-3 &&
    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. AlloyDB Omni を使用して my-omni-postgis という名前の新しいコンテナを作成します。

    Docker

    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. PostGIS 拡張機能を使用してデータベースに接続します。

    docker exec -it my-omni-postgis psql -h localhost -U postgres
  6. PostGIS を有効にします。

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

    出力は次のようになります。

       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)