Instala Orafce para AlloyDB Omni

AlloyDB Omni no incluye la extensión Orafce, pero puedes agregarla manualmente a una instalación existente de AlloyDB Omni. Para ello, sigue las instrucciones de esta página para proporcionar funciones y operadores adicionales desde la base de datos de Oracle.

Antes de comenzar

Asegúrate de haber instalado AlloyDB Omni en tu sistema.

Servidor único

Agrega Orafce a tu instalación de AlloyDB Omni

Para agregar la extensión Orafce a tu instalación de AlloyDB Omni, sigue estos pasos:

  1. Busca las etiquetas de versión de AlloyDB Omni instaladas:

    Docker

    docker run --rm -it  google/alloydbomni cat VERSION.txt

    Podman

    podman run --rm -it  google/alloydbomni cat VERSION.txt

    El resultado es similar a este:

    AlloyDB Omni version: 15.5.5
    

    Anota el número de versión de AlloyDB Omni, ya que lo necesitarás en el siguiente paso.

  2. Establece la variable de entorno OMNI_VERSION:
    OMNI_VERSION=VERSION

    Reemplaza VERSION por la versión completa del servidor de la base de datos del paso anterior, por ejemplo, 15.5.3.

  3. Crea un nuevo contenedor de AlloyDB Omni que incluya Orafce:

    Docker

      mkdir ~/alloydb-omni-orafce
      tee -a ~/alloydb-omni-orafce/Dockerfile << EOF
      ARG OMNI_VERSION
    
      FROM postgres:15-bookworm AS postgres
    
      RUN apt-get update && \
      apt-get install -y --no-install-recommends \
      postgresql-15-orafce && \
      apt-get purge -y --auto-remove && \
      rm -rf /var/lib/apt/lists/*
    
      FROM google/alloydbomni:${OMNI_VERSION}
    
      COPY --from=postgres /usr/lib/postgresql/15/lib/orafce.so /usr/lib/postgresql/15/lib/orafce.so
      COPY --from=postgres /usr/share/postgresql/15/extension/orafce* /usr/lib/postgresql/15/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/
      EOF
      cd ~/alloydb-omni-orafce
      sudo docker build --build-arg OMNI_VERSION=$OMNI_VERSION --tag google/alloydbomni-with-orafce:$OMNI_VERSION .
      

    Podman

      mkdir ~/alloydb-omni-orafce
      tee -a ~/alloydb-omni-orafce/Dockerfile << EOF
      ARG OMNI_VERSION
    
      FROM postgres:15-bookworm AS postgres
    
      RUN apt-get update && \
      apt-get install -y --no-install-recommends \
      postgresql-15-orafce && \
      apt-get purge -y --auto-remove && \
      rm -rf /var/lib/apt/lists/*
    
      FROM google/alloydbomni:${OMNI_VERSION}
    
      COPY --from=postgres /usr/lib/postgresql/15/lib/orafce.so /usr/lib/postgresql/15/lib/orafce.so
      COPY --from=postgres /usr/share/postgresql/15/extension/orafce* /usr/lib/postgresql/15/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/
      EOF
      cd ~/alloydb-omni-orafce
      sudo podman build --build-arg OMNI_VERSION=$OMNI_VERSION --tag google/alloydbomni-with-orafce:$OMNI_VERSION .
      

    Docker

      mkdir ~/alloydb-omni-orafce
      tee -a ~/alloydb-omni-orafce/Dockerfile << EOF
      ARG OMNI_VERSION
    
      FROM postgres:15-bookworm AS postgres
    
      RUN apt-get update && \
      apt-get install -y --no-install-recommends \
      postgresql-15-orafce && \
      apt-get purge -y --auto-remove && \
      rm -rf /var/lib/apt/lists/*
    
      FROM google/alloydbomni:${OMNI_VERSION}
    
      COPY --from=postgres /usr/lib/postgresql/15/lib/orafce.so /usr/lib/postgresql/15/lib/orafce.so
      COPY --from=postgres /usr/share/postgresql/15/extension/orafce* /usr/lib/postgresql/15/share/extension/
    
      COPY --from=postgres /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/
      COPY --from=postgres /lib/aarch64-linux-gnu/ /lib/aarch64-linux-gnu/
      EOF
      cd ~/alloydb-omni-orafce
      sudo docker build --build-arg OMNI_VERSION=$OMNI_VERSION --tag google/alloydbomni-with-orafce:$OMNI_VERSION .
      

    Podman

      mkdir ~/alloydb-omni-orafce
      tee -a ~/alloydb-omni-orafce/Dockerfile << EOF
      ARG OMNI_VERSION
    
      FROM postgres:15-bookworm AS postgres
    
      RUN apt-get update && \
      apt-get install -y --no-install-recommends \
      postgresql-15-orafce && \
      apt-get purge -y --auto-remove && \
      rm -rf /var/lib/apt/lists/*
    
      FROM google/alloydbomni:${OMNI_VERSION}
    
      COPY --from=postgres /usr/lib/postgresql/15/lib/orafce.so /usr/lib/postgresql/15/lib/orafce.so
      COPY --from=postgres /usr/share/postgresql/15/extension/orafce* /usr/lib/postgresql/15/share/extension/
    
      COPY --from=postgres /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/
      COPY --from=postgres /lib/aarch64-linux-gnu/ /lib/aarch64-linux-gnu/
      EOF
      cd ~/alloydb-omni-orafce
      sudo podman build --build-arg OMNI_VERSION=$OMNI_VERSION --tag google/alloydbomni-with-orafce:$OMNI_VERSION .
  4. Crea un contenedor nuevo con AlloyDB Omni llamado my-omni-orafce:

    Docker

    docker run --name my-omni-orafce  -e POSTGRES_PASSWORD=NEW_PASSWORD  -d google/alloydbomni-with-orafce:OMNI_VERSION

    Podman

    podman run --name my-omni-orafce  -e POSTGRES_PASSWORD=NEW_PASSWORD  -d google/alloydbomni-with-orafce:OMNI_VERSION
  5. Conéctate a tu base de datos con la extensión Orafce:

    Docker

    docker exec -it my-omni-orafce psql -h localhost -U postgres

    Podman

    podman exec -it my-omni-orafce psql -h localhost -U postgres
  6. Habilita Orafce:
    CREATE EXTENSION IF NOT EXISTS ORAFCE;
  7. Confirma que Orafce esté instalado y habilitado:
    SELECT oracle.sysdate();
    El resultado es similar al siguiente:
    postgres=# SELECT oracle.sysdate();
         sysdate
    ---------------------
    2024-06-10 16:36:30
    (1 row)