Sebelum memulai
Pastikan Anda memenuhi persyaratan sistem berikut:
Anda telah menginstal AlloyDB Omni di sistem Anda.
Anda telah menginstal CLI AlloyDB Omni di sistem Anda.
Menambahkan PostGIS ke penginstalan AlloyDB Omni
Untuk menambahkan ekstensi PostGIS ke penginstalan AlloyDB Omni Anda, ikuti langkah-langkah berikut:
- Temukan label versi AlloyDB Omni yang terinstal:
sudo alloydb version
Outputnya mirip dengan hal berikut ini:
AlloyDB Omni CLI version: 1.0 AlloyDB Omni database server version: 15.2.0
Catat nomor versi server database; Anda akan membutuhkannya di langkah berikutnya.
- Tetapkan variabel lingkungan
OMNI_VERSION
:OMNI_VERSION=VERSION
Ganti VERSION dengan versi server database lengkap dari langkah sebelumnya—misalnya,
15.2.0
. - Buat penampung AlloyDB Omni baru yang menyertakan PostGIS:
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 .
- Hentikan server database:
sudo alloydb database-server stop
- Buka
/var/alloydb/config/dataplane.conf
di editor teks. - Ubah baris yang menentukan variabel
PG_IMAGE
sehingga merujuk ke penampung yang Anda buat di langkah sebelumnya:PG_IMAGE=gcr.io/alloydb-omni/pg-service-with-postgis
- Mulai AlloyDB Omni:
sudo alloydb database-server start
- Hubungkan ke database Anda:
sudo docker exec -it pg-service psql -h localhost -U postgres
- Aktifkan PostGIS:
CREATE EXTENSION IF NOT EXISTS POSTGIS;