Instalar o orafce para o AlloyDB Omni

Selecione uma versão da documentação:

Nesta página, descrevemos como adicionar manualmente a extensão orafce a uma instalação do AlloyDB Omni. A extensão orafce fornece funções e operadores que emulam um subconjunto de funções e pacotes do banco de dados Oracle. Essa extensão simplifica a migração de aplicativos do Oracle para bancos de dados compatíveis com PostgreSQL, como o AlloyDB Omni.

Antes de começar

Instale o AlloyDB Omni no seu sistema.

Adicionar o orafce à instalação do AlloyDB Omni

Para adicionar a extensão orafce à sua instalação do AlloyDB Omni, siga estas etapas:

  1. Encontre os rótulos da versão instalada do AlloyDB Omni:

    Docker

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

    Podman

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

    O resultado será assim:

    AlloyDB Omni version: 16.3.0
    

    Anote o número da versão do AlloyDB Omni, porque você vai precisar dele na próxima etapa.

  2. Crie uma imagem do Docker personalizada que inclua a extensão orafce:

    $ ~/alloydb-omni-orafce
    
    $ cd ~/alloydb-omni-orafce
    
    $ cat <<EOF > Dockerfile
    FROM google/alloydbomni:16.3.0-ubi
    RUN arch=$(uname -m)
    RUN dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-$(arch)/pgdg-redhat-repo-latest.noarch.rpm
    RUN dnf install -y orafce_16
    
    # On RHEL-based systems, PostgreSQL extensions like Orafce and PostGIS are typically installed in /usr/pgsql-16/share/extension and /usr/pgsql-16/lib.
    # This step creates symbolic links to those files in the paths expected by AlloyDB Omni,
    # which lets AlloyDB Omni locate extension control files and shared libraries without duplicating data.
    RUN \
       for file in /usr/pgsql-16/share/extension/*; do \
       target="/usr/lib/postgresql/16/share/extension/$(realpath -m --relative-to=/usr/pgsql-16/share/extension/ "$file")"; \
       if [ ! -e "$target" ]; then \
          ln -s "$file" "$target" || (echo "Failed to link \"$file\" to \"$target\", exiting." && exit 1); \
       else \
          echo "$target already exists"; \
       fi; \
    done && \
    for file in /usr/pgsql-16/lib/*; do \
       target="/usr/lib/postgresql/16/lib/$(realpath -m --relative-to=/usr/pgsql-16/lib/ "$file")"; \
       if [ ! -e "$target" ]; then \
          ln -s "$file" "$target" || (echo "Failed to link \"$file\" to \"$target\", exiting." && exit 1); \
       else \
          echo "$target already exists"; \
       fi; \
    done
    EOF
    

  3. Crie um contêiner com o AlloyDB Omni chamado my-omni-orafce:

    docker build -t google/alloydbomni-with-orafce:latest
    docker run --name my-omni-orafce  -e POSTGRES_PASSWORD=NEW_PASSWORD  -d google/alloydbomni-with-orafce:OMNI_VERSION
    
  4. Conecte-se ao banco de dados com a extensão orafce:

    docker exec -it my-omni-orafce psql -h localhost -U postgres
    
  5. Ative o orafce:

    CREATE EXTENSION IF NOT EXISTS ORAFCE;
    
  6. Confirme se o orafce está instalado e ativado:

    SELECT oracle.sysdate();
    

    O resultado será assim:

    postgres=# SELECT oracle.sysdate();
    sysdate
    ---------------------
    2024-06-10 16:36:30
    (1 row)