為 AlloyDB Omni 安裝 PostGIS

選取文件版本:

AlloyDB Omni 不包含 PostGIS 擴充功能,但您可以按照本頁的操作說明,手動將其新增至現有的 AlloyDB Omni 安裝項目。

事前準備

確認符合下列系統需求:

在 AlloyDB Omni 安裝中新增 PostGIS

如要在 AlloyDB Omni 安裝中新增 PostGIS 擴充功能,請按照下列步驟操作:

  1. 找出已安裝的 AlloyDB Omni 版本標籤:
    sudo alloydb version

    輸出結果會與下列內容相似:

    AlloyDB Omni CLI version: 1.0
    AlloyDB Omni database server version: 15.2.0
    

    記下資料庫伺服器版本號碼,下一個步驟會用到。

  2. 設定 OMNI_VERSION 環境變數:
    OMNI_VERSION=VERSION

    VERSION 替換為上一個步驟中的完整資料庫伺服器版本,例如 15.2.0

  3. 建立包含 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 .

  4. 停止資料庫伺服器:
    sudo alloydb database-server stop
    
  5. 在文字編輯器中開啟 /var/alloydb/config/dataplane.conf
  6. 修改定義 PG_IMAGE 變數的行,使其參照您在上一個步驟中建構的容器:
    PG_IMAGE=gcr.io/alloydb-omni/pg-service-with-postgis
    
  7. 啟動 AlloyDB Omni:
    sudo alloydb database-server start
    
  8. 連線至資料庫:
    sudo docker exec -it pg-service psql -h localhost -U postgres
    
  9. 啟用 PostGIS:

    CREATE EXTENSION IF NOT EXISTS POSTGIS;