事前準備
確認您已在系統上安裝 AlloyDB Omni。
在 AlloyDB Omni 安裝中新增 PostGIS
如要將 PostGIS 擴充功能新增至 AlloyDB Omni 安裝項目,請按照下列步驟操作:
- 找出已安裝的 AlloyDB Omni 版本標籤:
  Dockerdocker run --rm -it google/alloydbomni cat VERSION.txt Podmanpodman run --rm -it google/alloydbomni cat VERSION.txt 輸出結果會與下列內容相似: AlloyDB Omni version: 15.7.0 記下 AlloyDB Omni 版本號碼,下一個步驟會用到。 
- 設定 OMNI_VERSION環境變數:OMNI_VERSION=VERSION 將 VERSION 替換為上一步的完整資料庫伺服器版本,例如 15.7.0。
- 建立包含 PostGIS 的新 AlloyDB Omni 容器:
   Linuxmkdir ~/alloydb-omni-postgistee -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/* EOFcd ~/alloydb-omni-postgissudo docker build --build-arg OMNI_VERSION=$OMNI_VERSION --tag google/alloydbomni-with-postgis:$OMNI_VERSION .macOSmkdir ~/alloydb-omni-postgistee -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/* EOFcd ~/alloydb-omni-postgissudo docker build --build-arg OMNI_VERSION=$OMNI_VERSION --tag google/alloydbomni-with-postgis:$OMNI_VERSION .
- 使用 AlloyDB Omni 建立名為 my-omni-postgis的新容器:Dockerdocker run --name my-omni-postgis -e POSTGRES_PASSWORD=NEW_PASSWORD -d google/alloydbomni-with-postgis:OMNI_VERSION Podmanpodman run --name my-omni-postgis -e POSTGRES_PASSWORD=NEW_PASSWORD -d google/alloydbomni-with-postgis:OMNI_VERSION 
- 使用 PostGIS 擴充功能連線至資料庫: - docker exec -it my-omni-postgis psql -h localhost -U postgres 
- 啟用 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)