התקנה של PostGIS ל-AlloyDB Omni

בחירת גרסה של מאמר העזרה:

בדף הזה מוסבר איך להוסיף באופן ידני את התוסף PostGIS להתקנה קיימת של AlloyDB Omni. התוסף PostGIS מאפשר לאחסן נתונים גיאו-מרחביים, ליצור להם אינדקסים ולהריץ עליהם שאילתות.

לפני שמתחילים

מתקינים את AlloyDB Omni במערכת.

אפשר להתקין את PostGIS באחת מהשיטות הבאות:

  • משתמשים באפשרויות של Debian ב-CLI של Docker או Podman. ‫Docker מסתמך על שירות רקע (daemon) ודורש הרשאות root לרוב הפעולות, בעוד ש-Podman לא מסתמך על שירות רקע ולא דורש הרשאות root.
  • שימוש בתמונות בסיס אוניברסליות (UBI) של Red Hat. תמונות של מערכת הפעלה בסיסית של קונטיינר UBI נוצרות מחלקים של Red Hat Enterprise Linux ‏ (RHEL).

הוספת PostGIS להתקנת AlloyDB Omni

כדי להוסיף את התוסף PostGIS להתקנת AlloyDB Omni, פועלים לפי השלבים הבאים:

  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: 17.5.0
    

    חשוב לשים לב למספר הגרסה של AlloyDB Omni כי תצטרכו אותו בשלב הבא.

  2. מגדירים את משתנה הסביבה OMNI_VERSION:

    OMNI_VERSION=VERSION
    

    מחליפים את VERSION בגרסה המלאה של שרת מסד הנתונים מהשלב הקודם, לדוגמה, 17.5.0.

  3. יוצרים קונטיינר חדש של AlloyDB Omni שכולל את PostGIS:

    Linux

    mkdir ~/alloydb-omni-postgis
    
    tee ~/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 ~/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)