始める前に
次のシステム要件を満たす必要があります。
システムに AlloyDB Omni がインストールされている。
AlloyDB Omni に PostGIS を追加する
AlloyDB Omni に PostGIS 拡張機能を追加する手順は次のとおりです。
- インストールされている AlloyDB Omni バージョンのラベルを確認します。
sudo alloydb version
出力は次のようになります。
AlloyDB Omni CLI version: 1.0 AlloyDB Omni database server version: 15.5.2
データベース サーバーのバージョン番号をメモします。これは次のステップで必要になります。
OMNI_VERSION
環境変数を設定します。OMNI_VERSION=VERSION
VERSION は、前の手順で確認したデータベース サーバーの完全なバージョンに置き換えます(例:
15.5.2
)。- PostGIS を含む新しい AlloyDB Omni コンテナを作成します。
mkdir ~/alloydb-omni-postgis
tee -a ~/alloydb-omni-postgis/Dockerfile << EOF ARG OMNI_VERSION FROM postgres:15-bookworm as postgres
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/*FROM gcr.io/alloydb-omni/pg-service:${OMNI_VERSION}
COPY --from=postgres /usr/lib/postgresql/15/lib/postgis-3.so /lib/postgis-3.so COPY --from=postgres /usr/lib/postgresql/15/lib/postgis_sfcgal-3.so /lib/postgis_sfcgal-3.so COPY --from=postgres /usr/lib/postgresql/15/lib/postgis_raster-3.so /lib/postgis_raster-3.so COPY --from=postgres /usr/lib/postgresql/15/lib/postgis_topology-3.so /lib/postgis_topology-3.so COPY --from=postgres /usr/lib/postgresql/15/lib/address_standardizer-3.so /lib/address_standardizer-3.so COPY --from=postgres /usr/share/postgresql/15/extension/address_standardizer* /share/extension/ COPY --from=postgres /usr/share/postgresql/15/extension/postgis* /share/extension/
COPY --from=postgres /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ COPY --from=postgres /lib/x86_64-linux-gnu/ /lib/x86_64-linux-gnu/
COPY --from=postgres /usr/lib/x86_64-linux-gnu/liblapack.so.3 /usr/lib/ COPY --from=postgres /usr/lib/x86_64-linux-gnu/libblas.so.3 /usr/lib/ COPY --from=postgres /usr/lib/libarmadillo.so.11 /usr/lib/ COPY --from=postgres /usr/lib/libmfhdfalt.so.0 /usr/lib/ COPY --from=postgres /usr/lib/libmfhdfalt.so.0 /usr/lib/ COPY --from=postgres /usr/lib/libdfalt.so.0 /usr/lib/ COPY --from=postgres /usr/lib/libogdi.so.4.1 /usr/lib/ COPY --from=postgres /usr/share/proj/proj.db /usr/share/proj/proj.db
EOF
cd ~/alloydb-omni-postgis
sudo docker build --build-arg OMNI_VERSION=$OMNI_VERSION --tag gcr.io/alloydb-omni/pg-service-with-postgis:$OMNI_VERSION .
- データベース サーバーを停止します。
sudo alloydb database-server stop
- テキスト エディタで
/var/alloydb/config/dataplane.conf
を開きます。 PG_IMAGE
変数を定義する行を変更して、前の手順でビルドしたコンテナを参照するようにします。PG_IMAGE=gcr.io/alloydb-omni/pg-service-with-postgis
- AlloyDB Omni を起動します。
sudo alloydb database-server start
- データベースに接続します。
sudo docker exec -it pg-service psql -h localhost -U postgres
- PostGIS を有効にします。
CREATE EXTENSION IF NOT EXISTS POSTGIS;