为 AlloyDB Omni 安装 orafce

选择文档版本:

本页面介绍了如何将 orafce 扩展程序手动添加到现有的 AlloyDB Omni 安装中。orafce 扩展程序提供模拟 Oracle 数据库中部分函数和软件包的函数和运算符。此扩展程序可简化将应用从 Oracle 迁移到与 PostgreSQL 兼容的数据库(如 AlloyDB Omni)的过程。

准备工作

在系统上安装 AlloyDB Omni

将 orafce 添加到 AlloyDB Omni 安装

如需将 orafce 扩展程序添加到 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: 16.8.0
    

    记下 AlloyDB Omni 版本号,因为您在下一步中需要用到它。

  2. 构建包含 orafce 扩展程序的自定义 Docker 映像:

    $ ~/alloydb-omni-orafce
    
    $ cd ~/alloydb-omni-orafce
    
    $ cat <<EOF > Dockerfile
    FROM google/alloydbomni:16.8.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. 创建一个名为 my-omni-orafce 的 AlloyDB Omni 容器:

    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. 使用 orafce 扩展程序连接到您的数据库:

    docker exec -it my-omni-orafce psql -h localhost -U postgres
    
  5. 启用 orafce:

    CREATE EXTENSION IF NOT EXISTS ORAFCE;
    
  6. 确认 orafce 已安装并已启用:

    SELECT oracle.sysdate();
    

    输出类似于以下内容:

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