OpenGauss 5.0.0 双机安装及ora2pg的使用

2024年 5月 28日 65.6k 0

点击上方“IT那活儿”公众号--专注于企业全栈运维技术分享,不管IT什么活儿,干就完了!!!   一

数据库介绍

1.1 版本说明

本次安装使用opengauss数据库的LTS版本 5.0.0,版本分为X86_64和AARCH64两个架构,安装建议使用当前最新LTS版本。

OpenGauss 5.0.0 双机安装及ora2pg的使用-1

1.2 架构介绍

1.2.1 数据库openGauss支持单机部署和一主多备部署两种部署形态

  • 单机指的是只有一个数据库实例。

  • 双机指的是系统中存在主备数据库实例,主实例支持读写,备实例支持只读。

  • 一主多备指的是在系统存在一个主机,多个备机,openGauss最多支持8个备机。

    冷备份:是指备份就是一个简单的备份集,不可以提供服务。

    热备份:是指备份实例可以对外提供服务 。

1.2.2 部署形态汇总

部署形态

技术方案

高可用

基础设置要求

业务场景

场景特点

技术规格

单机

单机

无高可用能力

单机房

物理机

对系统的可靠性和可用性无任何要求

主要用于体验试用以及调测场景

系统RTO和RPO不可控

无实例级容灾能力,一旦出现实例故障,系统不可用

一旦实例级数据丢失,则数据永久丢失,无法恢复

主备

主机+备机

抵御实例级故障

单机房

物理机

节点间无网络延迟

要求承受实例级故障

适用于对系统可靠性要求不高的场景

RPO=0

实例故障RTO python2.7
-rwxr-xr-x. 1 root root 14376 Jan 1  2022 python2.7
-rwxr-xr-x. 1 root root 1846 Jan 1  2022 python2.7-config
-rwxr-xr-x. 1 root root 14384 Jan 1  2022 python2.7-debug
-rwxr-xr-x. 1 root root 1852 Jan 1  2022 python2.7-debug-config
lrwxrwxrwx. 1 root root 16 Jan 1  2022 python2-config -> python2.7-config
lrwxrwxrwx. 1 root root 15 Jan 1  2022 python2-debug -> python2.7-debug
lrwxrwxrwx. 1 root root 22 Jan 1  2022 python2-debug-config -> python2.7-debug-config
lrwxrwxrwx. 1 root root 9 Jan 1  2022 python3 -> python3.7
-rwxr-xr-x. 2 root root 14376 Jan 1  2022 python3.7
-rwxr-xr-x. 2 root root 14376 Jan 1  2022 python3.7m
-rwxr-xr-x. 1 root root 388 Jan 1  2022 python3-chardetect
lrwxrwxrwx. 1 root root 7 Jan 1  2022 python.bak -> python2
lrwxrwxrwx. 1 root root 14 Jan 1  2022 python-config -> python2-config
lrwxrwxrwx. 1 root root 13 Jan 1  2022 python-debug -> python2-debug
lrwxrwxrwx. 1 root root 20 Jan 1  2022 python-debug-config -> python2-debug-config
root@host-02[/usr/bin]python -V
Python 3.7.9

2.8 创建XML配置文件

需要提前创建安装时使用的配置文件,配置文件里有对应命名和目录结构参数配置。

omm@host-02[~]cat cluster_config.xml

  
    
    
    
    
    
    
    
    
  
  
  
    
      
      
      
      
      
      
      
      
      
      
    

    
      
      
      
      
      
    
  

2.9 节点配置互信

配置两个节点omm用户的互信。

2.10 安装前检查

root@host-01[/home/omm/software/script]./gs_preinstall -U omm -G dbgrp -L -X /home/omm/cluster_config.xml

Parsing the configuration file.
Successfully parsed the configuration file.
Installing the tools on the local node.
Successfully installed the tools on the local node.
Setting host ip env
Successfully set host ip env.
Preparing SSH service.
Successfully prepared SSH service.
Checking OS software.
Successfully check os software.
Checking OS version.
Successfully checked OS version.
Creating cluster's path.
Successfully created cluster's path.
Set and check OS parameter.
Setting OS parameters.
Successfully set OS parameters.
Warning: Installation environment contains some warning messages.
Please get more details by "/home/omm/software/script/gs_checkos -i A -h host-01 --detail".
Set and check OS parameter completed.
Preparing CRON service.
Successfully prepared CRON service.
Setting user environmental variables.
Successfully set user environmental variables.
Setting the dynamic link library.
Successfully set the dynamic link library.
Setting Core file
Successfully set core path.
Setting pssh path
Successfully set pssh path.
Setting Cgroup.
Successfully set Cgroup.
Set ARM Optimization.
No need to set ARM Optimization.
Fixing server package owner.
Setting finish flag.
Successfully set finish flag.
Preinstallation succeeded.

预检查通过后,可以进行下一步安装动作。

2.11 执行安装

指定参数启动数据库,内存、进程和字符集等参数,主节点执行即可。

gs_install -X /home/omm/cluster_config.xml --gsinit-parameter="--encoding=UTF8" --dn-guc="max_process_memory=4GB" 
--dn-guc="shared_buffers=256MB" --dn-guc="bulk_write_ring_size=256MB" 
--dn-guc="cstore_buffers=16MB"

Parsing the configuration file.
Check preinstall on every node.
Successfully checked preinstall on every node.
Creating the backup directory.
Last time end with Install cluster.
Continue this step.
Successfully created the backup directory.
begin deploy..
Rolling back.
Rollback succeeded.
Installing the cluster.
begin prepare Install Cluster..
Checking the installation environment on all nodes.
begin install Cluster..
Installing applications on all nodes.
Successfully installed APP.
begin init Instance..
encrypt cipher and rand files for database.
Please enter password for database:
Please repeat for database:
begin to create CA cert files
The sslcert will be generated in /opt/opengauss/install/app/share/sslcert/om
NO cm_server instance, no need to create CA for CM.
Non-dss_ssl_enable, no need to create CA for DSS
Cluster installation is completed.
Configuring.
Deleting instances from all nodes.
Successfully deleted instances from all nodes.
Checking node configuration on all nodes.
Initializing instances on all nodes.
Updating instance configuration on all nodes.
Check consistence of memCheck and coresCheck on database nodes.
Successful check consistence of memCheck and coresCheck on all nodes.
Configuring pg_hba on all nodes.
Configuration is completed.
The cluster status is Normal.
Successfully started cluster.
Successfully installed application.
end deploy..
omm@host-01[~]

2.12 状态检查

安装完成后执行gs_om命令检查状态。

omm@host-01[/opt/opengauss/install/app/bin]gs_om -t status --detail
[ Cluster State ]

cluster_state : Normal
redistributing : No
current_az : AZ_ALL

[ Datanode State ]

node node_ip port instance                               state

----------------------------------------------------------------------------------------------------------

1  host-01 11.11.xx.183    15400      6001 /opt/opengauss/install/data/dn P Primary Normal
2  host-02 11.11.xx.184    15400      6002 /opt/opengauss/install/data/dn S Standby Normal

2.13 备库只读

设置备库只读。

1)如果主备机上的openGauss数据库实例正在运行,请先分别停止主备机上的数据库实例。

2)分别打开主机与备机的postgresql.conf配置文件,找到并将对应参数修改为:

wal_level=hot_standby
hot_standby = on
hot_standby_feedback = on

3)参数max_standby_streaming_delay、 max_prepared_transactions、 max_standby_archive_delay、 hot_standby_feedback可以参考《数据库参考》按需进行设置。

4)修改完成后,分别启动主备机即可。

2.14 取消public 权限

创建用户后,取消public权限,同时创建一个与用户名相同的schema,创建对象默认放到该schema下。

revoke all on schema public  from public;
create user user1 login identified by "passwd1";
grant all privileges on database db1 to user1;

2.15 高可用切换测试

进行主备切换测试,以及主备故障恢复测试。

## 切主操作。

#在备库执行:

omm@host-02[~]gs_om -t status --detail
[ Cluster State ]

cluster_state : Normal
redistributing : No
current_az : AZ_ALL

[ Datanode State ]

    node node_ip port instance state
----------------------------------------------------------------------------------------------------------
1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Primary Normal
2 host-02 11.11.11.184 15400 6002 /opt/opengauss/install/data/dn S Standby Normal

omm@host-02[~]gs_ctl switchover -D /opt/opengauss/install/data/dn
[2023-12-19 23:10:18.450][160831][][gs_ctl]: gs_ctl switchover ,datadir is /opt/opengauss/install/data/dn
[2023-12-19 23:10:18.450][160831][][gs_ctl]: switchover term (1)
[2023-12-19 23:10:18.456][160831][][gs_ctl]: waiting for server to switchover........
[2023-12-19 23:10:23.493][160831][][gs_ctl]: done
[2023-12-19 23:10:23.493][160831][][gs_ctl]: switchover completed (/opt/opengauss/install/data/dn)
omm@host-02[~]gs_om -t status --detail
[ Cluster State ]

cluster_state : Normal
redistributing : No
current_az : AZ_ALL

[ Datanode State ]

    node node_ip port instance state
----------------------------------------------------------------------------------------------------------
1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Standby Normal
2 host-02 11.11.11.184 15400 6002 /opt/opengauss/install/data/dn S Primary Normal

omm@host-02[~]gs_om -t refreshconf ## 一定要更新配置

Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.

##回切操作:

omm@host-01[~]gs_ctl switchover -D /opt/opengauss/install/data/dn

[2023-12-19 23:11:33.767][307027][][gs_ctl]: gs_ctl switchover ,datadir is /opt/opengauss/install/data/dn
[2023-12-19 23:11:33.767][307027][][gs_ctl]: switchover term (1)
[2023-12-19 23:11:33.773][307027][][gs_ctl]: waiting for server to switchover........
[2023-12-19 23:11:38.811][307027][][gs_ctl]: done
[2023-12-19 23:11:38.811][307027][][gs_ctl]: switchover completed (/opt/opengauss/install/data/dn)
omm@host-01[~]
omm@host-01[~]gs_om -t refreshconf
Generating dynamic configuration file for all nodes.
Successfully generated dynamic configuration file.

omm@host-01[~]gs_om -t status --detail

[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip port instance state

----------------------------------------------------------------------------------------------------------

1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Primary Normal
2  host-02 11.11.11.184    15400      6002 /opt/opengauss/install/data/dn S Standby Normal
omm@host-01[~]

## 失败切换。

# 停掉主库:

omm@host-01[~]gs_om -t status --detail

[ Cluster State ]
cluster_state : Unavailable
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
node node_ip port instance state

----------------------------------------------------------------------------------------------------------

1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Down Manually stopped
2  host-02 11.11.11.184    15400      6002 /opt/opengauss/install/data/dn S Standby Need repair(Disconnected)

# 备库强制切主:

omm@host-02[~]gs_ctl failover -D /opt/opengauss/install/data/dn

[2023-12-19 23:14:16.444][172210][][gs_ctl]: gs_ctl failover ,datadir is /opt/opengauss/install/data/dn
[2023-12-19 23:14:16.444][172210][][gs_ctl]: failover term (1)
[2023-12-19 23:14:16.449][172210][][gs_ctl]: waiting for server to failover...
.[2023-12-19 23:14:17.460][172210][][gs_ctl]: done
[2023-12-19 23:14:17.460][172210][][gs_ctl]: failover completed (/opt/opengauss/install/data/dn)

omm@host-02[~]gs_om -t status --detail

[ Cluster State ]
cluster_state : Degraded
redistributing : No
current_az : AZ_ALL
[ Datanode State ]
    node node_ip port instance state
----------------------------------------------------------------------------------------------------------
1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Down Manually stopped
2  host-02 11.11.11.184    15400      6002 /opt/opengauss/install/data/dn S Primary Normal
omm@host-02[~]

#  原主库启动后,加入复制关系:

omm@host-01[~] gs_ctl start -D /opt/opengauss/install/data/dn -M standby

[2023-12-19 23:15:14.417][314811][][gs_ctl]: gs_ctl started,datadir is /opt/opengauss/install/data/dn
[2023-12-19 23:15:14.441][314811][][gs_ctl]: waiting for server to start...
.0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env.
[2023-12-19 23:15:15.448][314811][][gs_ctl]: server started (/opt/opengauss/install/data/dn)
omm@host-01[~]gs_om -t status --detail
[ Cluster State ]

cluster_state : Degraded
redistributing : No
current_az : AZ_ALL

[ Datanode State ]

    node node_ip port instance state
----------------------------------------------------------------------------------------------------------
1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Standby Need repair(WAL)
2 host-02 11.11.11.184 15400 6002 /opt/opengauss/install/data/dn S Primary Normal

omm@host-01[~]gs_ctl build -D /opt/opengauss/install/data/dn

[2023-12-19 23:15:47.397][316058][dn_6001_6002][gs_ctl]: fprintf build pid file "/opt/opengauss/install/data/dn/gs_build.pid" success
[2023-12-19 23:15:47.399][316058][dn_6001_6002][gs_ctl]: fsync build pid file "/opt/opengauss/install/data/dn/gs_build.pid" success

omm@host-01[~]gs_om -t status --detail

[ Cluster State ]
cluster_state : Normal
redistributing : No
current_az : AZ_ALL

[ Datanode State ]

    node node_ip port instance state
----------------------------------------------------------------------------------------------------------
1 host-01 11.11.11.183 15400 6001 /opt/opengauss/install/data/dn P Standby Normal
2  host-02 11.11.11.184    15400      6002 /opt/opengauss/install/data/dn S Primary Normal

2.16 参数优化

password_encryption_type,因客户端访问时不支持新的密码加密方式,修改为1兼容之前版本。

gs_guc reload -N all -I all -c "password_encryption_type=1"
gs_guc reload -N all -I all -c "password_reuse_max=3"
gs_guc reload -N all -I all -c "enable_memory_limit=on"
gs_guc reload -N all -I all -c "work_mem=512MB"
gs_guc reload -N all -I all -c "maintenance_work_mem=512MB"
gs_guc reload -N all -I all -c "bulk_read_ring_size=512MB"
gs_guc reload -N all -I all -c "bulk_write_ring_size=512MB" ?
gs_guc reload -N host-01 -D /opt/opengauss/install/data/dn -c "max_process_memory=16GB"
gs_guc reload -N host-02 -D /opt/opengauss/install/data/dn -c "max_process_memory=8GB"
gs_guc reload -N host-02 -D /opt/opengauss/install/data/dn -c "work_mem=1GB"
gs_guc reload -N host-01 -D /opt/opengauss/install/data/dn -c "shared_buffers=10GB"
gs_guc reload -N host-02 -D /opt/opengauss/install/data/dn -c "shared_buffers=4GB"

omm@host-01[~]gs_om -t restart #重启生效

Stopping cluster.

=========================================

Successfully stopped cluster.

=========================================

End stop cluster.

Starting cluster.

=========================================

[SUCCESS] host-01

2023-12-20 10:38:08.725 65825390.1 [unknown] 139684122632128 [unknown] 0 dn_6001_6002 01000  0 [BACKEND] WARNING: could not create any HA TCP/IP sockets

[SUCCESS] host-02

2023-12-20 10:38:12.216 65825394.1 [unknown] 139862630883264 [unknown] 0 dn_6001_6002 01000  0 [BACKEND] WARNING: could not create any HA TCP/IP sockets

=========================================

Successfully started.

2.17 错误处理

omm@host-01[~]export TMOUT=0

omm@host-01[~]gs_install -X /home/omm/cluster_config.xml --
gsinit-parameter="--encoding=UTF8" --dn-
guc="max_process_memory=4GB" --dn-guc="shared_buffers=256MB" --dn-guc="bulk_write_ring_size=256MB" --dn-guc="cstore_buffers=16MB"

Parsing the configuration file.

Check preinstall on every node.

[GAUSS-51400] : Failed to execute the command: python3
'/opt/opengauss/install/om/script/local/CheckPreInstall.py' -U omm -t preinstall. Result:{'host-01': 'Failure', 'host-02': 'Success'}.

Error:

[FAILURE] host-01:

[SUCCESS] host-02:

Successfully checked GAUSS_ENV.

需要手工执行验证互信,包括本机和远端,两节点一样操作:

omm@host-01[~]python3 '/opt/opengauss/install/om/script/local/CheckPreInstall.py' -U omm -t preinstall
Successfully checked GAUSS_ENV.
omm@host-01[~]ssh host-01 date
The authenticity of host 'host-01 (11.11.11.183)' can't be established.
ECDSA key fingerprint is SHA256:ei10qMITbfPdLiU7EJ1WdJZfzCPcj/6U60ckhXQKfO8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'host-01,11.11.11.183' (ECDSA) to the list of known hosts.

Authorized users only. All activities may be monitored and reported.
Mon Dec 18 14:45:33 CST 2023
omm@host-01[~]ssh host-01 date
Authorized users only. All activities may be monitored and reported.
Mon Dec 18 14:45:35 CST 2023
omm@host-01[~]ssh host-02 date

数据迁移(ora2pg)

3.1 安装ora2pg

yum install perl-ExtUtils-CBuilder
yum install perl-ExtUtils-MakeMaker
yum install perl-CPAN
rpm -ivh oracle-instantclient19.11-basic-19.11.0.0.0-1.x86_64.rpm
rpm -ivh oracle-instantclient19.11-devel-19.11.0.0.0-1.x86_64.rpm
rpm -ivh oracle-instantclient19.11-jdbc-19.11.0.0.0-1.x86_64.rpm
rpm -ivh oracle-instantclient19.11-sqlplus-19.11.0.0.0-1.x86_64.rpm
export ORACLE_HOME=/usr/lib/oracle/19.11/client64/

#安装DBI,DBD::Oracle,DBD::Pg ,在 www.cpan.org/modules/by-module 进行下载,版本选择最近版本。

  • DBD-Oracle-1.83.tar.gz

  • DBI-1.643.tar.gz

  • DBD-Pg-3.18.0.tar.gz

#在安装前需要设置环境变量:

export ORACLE_HOME=/usr/lib/oracle/19.11/client64/
export GAUSSHOME=/opt/opengauss/install/app/
export C_INCLUDE_PATH=/opt/opengauss/install/app_a07d57c3/include/p
ostgresql/server/libpq/:/opt/opengauss/install/app_a07d57c3/include/postgresql/server/

#分别解压后,执行:

perl Makefile.PL
make && make install

# 安装JSON:

JSON-4.10.tar.gz
perl Makefile.PL
make && make install

## 源码安装:

perl Makefile.PL
make && make install
export PERL5LIB=/home/omm/software/ora2og/openGauss-tools-ora2og-master/
export PATH=$PATH:/usr/local/bin/
ora2pg --help

root@host-01[/home/omm/software]ora2pg -v
Ora2Pg v21.1

3.2 软件环境检查

使用下面提供的脚本检查当前安装组件是否正确。

vi check.pl
#!/usr/bin/perl
use strict;
use ExtUtils::Installed;

my $inst=ExtUtils::Installed->new();
my @modules=$inst->modules();

foreach(@modules)
{
  my $ver = $inst->version($_)||"????";
  printf("%-12s -- %s\n", $_, $ver);
}
exit;

root@host-01[/usr/local/bin]perl check.pl
DBD::Oracle -- 1.83
DBD::Pg -- 3.18.0
DBI -- 1.643
JSON -- 4.10
Ora2Pg -- 21.1
Perl -- 5.28.3
RRDs -- 1.6999

3.3 项目初始化

Ora2pg可以针对每次迁移任务创建一个逻辑项目,项目下有对应目录存放迁移过程中的数据和文件。

root@host-01[/home/omm/ora2pg]ora2pg --init_project dir1

Creating project dir1.
./dir1/
        schema/
                dblinks/
                directories/
                functions/
                grants/
                mviews/
                packages/
                partitions/
                procedures/
                sequences/
                synonyms/
                tables/
                tablespaces/
                triggers/
                types/
                views/
        sources/
                functions/
                mviews/
                packages/
                partitions/
                procedures/
                triggers/
                types/
                views/
        data/
        config/
        reports/

Generating generic configuration file
Creating script export_schema.sh to automate all exports.
Creating script import_all.sh to automate all imports.

3.4 编辑配置文件

root@host-01[/etc/ora2pg]cat ora2pg.conf

ORACLE_HOME /usr/lib/oracle/19.11/client64/
ORACLE_DSN dbi:Oracle:host=10.19.190.90;sid=reportdb;port=1521
ORACLE_USER csprpt6
ORACLE_PWD KFQ_kf4
USER_GRANTS 0
DEBUG 0
EXPORT_SCHEMA 0
CREATE_SCHEMA 1
COMPILE_SCHEMA 0
NO_FUNCTION_METADATA 0
TYPE TABLE
DISABLE_COMMENT 0
NO_VIEW_ORDERING 0
EXTERNAL_TO_FDW 1
TRUNCATE_TABLE 0
USE_TABLESPACE 0
REORDERING_COLUMNS 0
CONTEXT_AS_TRGM 0
FTS_INDEX_ONLY 1
USE_UNACCENT 0
USE_LOWER_UNACCENT 0
DATADIFF 0
DATADIFF_UPDATE_BY_PKEY 0
DATADIFF_DEL_SUFFIX _del
DATADIFF_UPD_SUFFIX _upd
DATADIFF_INS_SUFFIX _ins
DATADIFF_WORK_MEM 512 MB
DATADIFF_TEMP_BUFFERS 1024 MB
KEEP_PKEY_NAMES 0
PKEY_IN_CREATE 0
FKEY_ADD_UPDATE never
FKEY_DEFERRABLE 0
DEFER_FKEY 0
DROP_FKEY 0
DISABLE_SEQUENCE 0
DISABLE_TRIGGERS 0
PRESERVE_CASE 0
INDEXES_RENAMING 0
USE_INDEX_OPCLASS 0
PREFIX_PARTITION 0
PREFIX_SUB_PARTITION 1
DISABLE_PARTITION 0
WITH_OID 0
ORA_RESERVED_WORDS audit,comment,references
USE_RESERVED_WORDS 0
DISABLE_UNLOGGED 0
OUTPUT          output.sql
BZIP2
FILE_PER_CONSTRAINT 0
FILE_PER_INDEX 0
FILE_PER_FKEYS 0
FILE_PER_TABLE 0
FILE_PER_FUNCTION 0
STOP_ON_ERROR 1
COPY_FREEZE 0
CREATE_OR_REPLACE 1
PG_NUMERIC_TYPE 1
PG_INTEGER_TYPE 1
DEFAULT_NUMERIC bigint
ENABLE_MICROSECOND 1
TO_NUMBER_CONVERSION numeric
GEN_USER_PWD 0
FORCE_OWNER 0
FORCE_SECURITY_INVOKER 0
DATA_LIMIT 10000
NOESCAPE 0
TRANSACTION     serializable
STANDARD_CONFORMING_STRINGS 1
USE_LOB_LOCATOR 1
LOB_CHUNK_SIZE 512000
XML_PRETTY 0
LOG_ON_ERROR 0
TRIM_TYPE BOTH
INTERNAL_DATE_MAX 49
FUNCTION_CHECK 1
ENABLE_BLOB_EXPORT 1
DATA_EXPORT_ORDER name
PSQL_RELATIVE_PATH 0
JOBS 1
ORACLE_COPIES 1
PARALLEL_TABLES 1
DEFAULT_PARALLELISM_DEGREE 0
PARALLEL_MIN_ROWS 100000
DROP_INDEXES 0
SYNCHRONOUS_COMMIT 0
EXPORT_INVALID 0
PLSQL_PGSQL 1
NULL_EQUAL_EMPTY 0
EMPTY_LOB_NULL 1
PACKAGE_AS_SCHEMA 1
REWRITE_OUTER_JOIN 1
FUNCTION_STABLE 1
COMMENT_COMMIT_ROLLBACK 0
COMMENT_SAVEPOINT 0
USE_ORAFCE 0
AUTONOMOUS_TRANSACTION 1
ESTIMATE_COST 0
COST_UNIT_VALUE 5
DUMP_AS_HTML 0
TOP_MAX 10
HUMAN_DAYS_LIMIT 5
PG_VERSION 12
BITMAP_AS_GIN 1
PG_BACKGROUND 0
PG_SUPPORTS_SUBSTR 1
AUTODETECT_SPATIAL_TYPE 1
CONVERT_SRID 1
DEFAULT_SRID 4326
GEOMETRY_EXTRACT_TYPE INTERNAL
FDW_SERVER orcl
MYSQL_PIPES_AS_CONCAT 0
MYSQL_INTERNAL_EXTRACT_FORMAT 0

## 验证:

root@host-01[/etc/ora2pg]ora2pg -t SHOW_VERSION -c ora2pg.conf
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0

3.5 数据迁移

本次只针对几张表和几个存储过程迁移,分别使用结构转换和数据同步功能。

ora2pg -t TABLE -a T1,T2,T3 -c /etc/ora2pg/ora2pg.conf

root@host-01[/etc/ora2pg]ora2pg -t TABLE -a T1,T2,T3 -c /etc/ora2pg/ora2pg.conf
[========================>] 12/12 tables (100.0%) end of scanning.
Retrieving table partitioning information...
[========================>] 12/12 tables (100.0%) end of table export.

##存储过程处理
P1,P2,P3A
root@host-01[/home/omm/ora2pg/dir1]sh export_schema.sh
[========================>] 685/685 tables (100.0%) end of scanning.
[========================>] 13/13 objects types (100.0%) end of objects auditing.
Running: ora2pg -p -t TABLE -a T1,T2,T3 -o table.sql -b ./schema/tables -c ./config/ora2pg.conf

[========================>] 12/12 tables (100.0%) end of scanning.
Retrieving table partitioning information...
[========================>] 12/12 tables (100.0%) end of table export.
Running: ora2pg -p -t PROCEDURE -a P1,P2,P3 A -o procedure.sql -b ./schema/procedures -c ./config/ora2pg.conf

[========================>] 8/8 procedures (100.0%) end of procedures export.
Running: ora2pg -t PROCEDURE -a P1,P2,P3 A -o procedure.sql -b ./sources/procedures -c ./config/ora2pg.conf
[========================>] 8/8 procedures (100.0%) end of procedures export.

##上面定义转换完成后,可以在目标端执行。

To extract data use the following command:
ora2pg -t COPY -a T1,T2,T3 -o data.sql -b ./data -c ./config/ora2pg.conf
sh import_all.sh -d db1 -o user1 -w xxxx -p 15400 -h 127.0.0.1 -f
ora2pg -p -t TABLE -a T1,T2,T3 -o tales2.sql -b ./schema/tables -c ./config/ora2pg.conf

3.6 错误处理

root@host-01[/home/omm/software/ora2og/DBD-Pg-3.18.0]make
cp lib/Bundle/DBD/Pg.pm blib/lib/Bundle/DBD/Pg.pm
cp Pg.pm blib/lib/DBD/Pg.pm
Running Mkbootstrap for Pg ()
chmod 644 "Pg.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Pg.bs blib/arch/auto/DBD/Pg/Pg.bs 644
"/usr/bin/perl" -p -e "s/~DRIVER~/Pg/g; s/^do\(/dontdo\(/" /usr/local/lib64/perl5/auto/DBI/Driver.xst > Pg.xsi
"/usr/bin/perl" "/usr/share/perl5/vendor_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/ExtUtils/typemap'  Pg.xs > Pg.xsc
mv Pg.xsc Pg.c

gcc -c -I/opt/opengauss/install/app/include -I/usr/local/lib64/perl5/auto/DBI -D_REENTRANT
-D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,
-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1
-m64 -mtune=generic -fasynchronous-unwind-tables
-fstack-clash-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -DPGLIBVERSION=90204 -DPGDEFPORT=5432 
-g -DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc -Dfree=Perl_mfree -Drealloc=Perl_realloc -Dcalloc=Perl_calloc
-DVERSION=\"3.18.0\" -DXS_VERSION=\"3.18.0\" -fPIC "-I/usr/lib64/perl5/CORE" Pg.c

In file included from Pg.xs:14:0:
Pg.h:35:10: fatal error: libpq-fe.h: No such file or directory
 #include "libpq-fe.h"
          ^~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:359: Pg.o] Error 1

export
C_INCLUDE_PATH=/opt/opengauss/install/app_a07d57c3/include/postgresql/server/libpq/:/opt/opengauss/install/app_a07d57c3/include/postgresql/server/

omm@host-01[~]ora2pg --help
Can't locate JSON.pm in @INC (you may need to install the JSON module) (@INC contains: /usr/local/lib64/perl5
/usr/local/share/perl5 /usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl /usr/lib64/perl5
/usr/share/perl5) at /usr/local/share/perl5/Ora2Pg.pm line 41.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Ora2Pg.pm line 41.
Compilation failed in require at /usr/local/bin/ora2pg line 27.
BEGIN failed--compilation aborted at /usr/local/bin/ora2pg line 27.
omm@host-01[~]timed out waiting for input: auto-logout
JSON-4.10]perl Makefile.PL
JSON-4.10]make && make install

OpenGauss 5.0.0 双机安装及ora2pg的使用-2END

本文作者:孙其成(上海新炬中北团队)

本文来源:“IT那活儿”公众号

OpenGauss 5.0.0 双机安装及ora2pg的使用-3

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论