為 AlloyDB Omni 安裝 PostGIS

選取說明文件版本:

本頁面說明如何手動將 PostGIS 擴充功能新增至現有的 AlloyDB Omni 安裝項目。PostGIS 擴充功能可儲存、建立索引及查詢地理空間資料。

你可以使用下列任一方法安裝 PostGIS:

  • 在 Docker 或 Podman CLI 中使用 Debian 選項。Docker 依賴精靈,且大多數作業都需要 root 權限,而 Podman 則不需要精靈和 root 權限。
  • 使用 Red Hat Universal Base Images (UBI)。UBI 容器基礎作業系統映像檔是根據 Red Hat Enterprise Linux (RHEL) 的部分內容建構而成。

事前準備

在系統上安裝 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: 16.8.0
    

    記下 AlloyDB Omni 版本號碼,因為下一個步驟會用到。

  2. 設定 OMNI_VERSION 環境變數:

    OMNI_VERSION=VERSION
    

    VERSION 替換為上一步的完整資料庫伺服器版本,例如 16.8.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-16-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-16-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 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. 使用 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)