导出导入数据
导出数据
编写配置文件
ora2pg 导出数据的配置文件如下:
cat > shcrm_so1_data.conf << EOF ORACLE_HOME /home/postgres/oracle/instantclient_11_2 ORACLE_DSN dbi:Oracle:host=10.10.141.225;sid=shcrm1 ORACLE_USER so1 ORACLE_PWD Csxt-123 SCHEMA so1 TYPE COPY OUTPUT_DIR /adbdata/ora2pg/data/so1 USER_GRANTS 1 FILE_PER_TABLE 1 SPLIT_FILE 1 DISABLE_SEQUENCE 1 STOP_ON_ERROR 0 ORACLE_COPIES 10 DATA_LIMIT 100000 SPLIT_LIMIT 10000000 WHERE expire_date >= to_date('2015/06/01 00:00:00','yyyy/MM/dd hh24:mi:ss') and expire_date < to_date('2016/07/01 00:00:00','yyyy/MM/dd hh24:mi:ss') EOF
复制
OUTPUT_DIR 指定了导出sql文件的存放目录。
WHERE 指定了导出时候对数据的过滤条件,如果需要全表数据导出,则去掉该参数。
创建相关目录
mkdir -p /adbdata/ora2pg/data/{so1,so2,party}/import_done
import_done 存放各个用户下,导入完成后的sql文件。
导出数据
在迁移涉及到的表数量比较多的时候,建议采用表的方式来记录迁移表的信息,方便查询表的迁移状态。
创建配置表
创建配置表用来存放迁移表的信息:
create table t_ora2adb_tableinfo ( dbname text, owner text, tablename text, batch_tag text, o_cnt numeric, a_cnt numeric, o_cnt_time timestamp, a_cnt_time timestamp, o_minus_a numeric, a_minus_o numeric, o_size_m numeric, a_size_m numeric, is_export numeric, export_time timestamp, where_filter text );
复制
初始化配置表
insert into t_ora2adb_tableinfo (dbname,owner,tablename,is_export) select 'shhis',a.tableowner,a.tablename,0 from pg_tables a where 1=1 and a.tableowner not in ('postgres','') and a.schemaname not in ('public','pg_catalog','information_schema') and a.tablename like 'sec%'; ;
复制
更新配置表字段
字段is_export的值在初始化的时候设置为0,需要更新该字段为1或者更新其他字段,则通过update语句来操作:
update t_ora2adb_tableinfo set xx=xx where xx ..
复制
编写导出脚本
vi ora2pg_export.sh #!/bin/bash # ora2pg export # ora2pg config: shhis_data.conf # sh ora2pg_export.sh owner tablenamelike tablecnt # sh ora2pg_export.sh configfile username tablename logdir tablecnt function check_ora_conn { conn_tag=`sqlplus -S /nolog <<EOF set heading off feedback off pagesize 0 verify off echo off conn $oraconn select * from dual; exit EOF` if [ "x$conn_tag" = "x" ]; then echo "the oracle connection is invalid!" exit(0) else echo "the oracle connection is ok!" fi } function check_ora2pg { which ora2pg if [ $? -eq 0 ]; then return 0 else echo "ora2pg execute program not find!" exit fi } function check_ora2pgcfg { if [ -f "$configfile" ]; then return 0 else echo "ora2pg config file does not exist!" exit fi } function init_tablecnt { if [ "x$tablecnt" = "x" ]; then echo "tablecnt apply init value:10" tablecnt=10 fi } function ora2pg_background { selectsql="select tablename from t_ora2adb_tableinfo where dbname='$dbname' and owner='$tableowner' and tablename like '%$tablelike%' and is_export=0 limit $tablecnt;" tables=(`$psqlconn -c "$selectsql"`) for t in ${tables[@]} do updatesql="update t_ora2adb_tableinfo set is_export=1,export_time=now() where owner='$tableowner' and tablename='$t'" $psqlconn -c "$updatesql" ora2pg -c $configfile -n $tableowner -a"$t" -d > ${logdir}/"ora2pg_"$tableowner_$t.log 2>&1 & echo "ora2pg to export table: $tableowner.$t" done } # init parameter configfile=$1 username=$2 tablelike=$3 logdir=$4 tablecnt=$5 tableowner="$username" dbname="shcrm1" # Make sure this option is correct,If the oracle database is not connected, the program will exit oraconn="$username/Csxt-123@10.10.141.225/shcrm" psqlconn="psql -d $dbname -U $tableowner -q -t" check_ora2pg check_ora2pgcfg init_tablecnt ora2pg_background
复制
执行导出操作
sh ora2pg_export.sh /adbdata/ora2pg/conf/shcrm_so1_data.conf so1 ord_user_ext_f_210_201612 /adbdata/ora2pg/log 3
复制
AntDB数据库始于2008年,在运营商的核心系统上,为全国24个省份的10亿多用户提供在线服务,具备高性能、弹性扩展、高可靠等产品特性,峰值每秒可处理百万笔电信核心交易,保障系统持续稳定运行近十年,并在通信、金融、交通、能源、物联网等行业成功商用落地。
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
数据库国产化替代深化:DBA的机遇与挑战
代晓磊
1203次阅读
2025-04-27 16:53:22
2025年3月国产数据库中标情况一览:TDSQL大单622万、GaussDB大单581万……
通讯员
885次阅读
2025-04-10 15:35:48
【专家有话说第六期】数据库考证到底有用么?国产时代DBA如何构建真实竞争力
墨天轮编辑部
871次阅读
2025-05-06 17:50:06
2025年4月国产数据库中标情况一览:4个千万元级项目,GaussDB与OceanBase大放异彩!
通讯员
686次阅读
2025-04-30 15:24:06
数据库,没有关税却有壁垒
多明戈教你玩狼人杀
586次阅读
2025-04-11 09:38:42
天津市政府数据库框采结果公布,7家数据库产品入选!
通讯员
574次阅读
2025-04-10 12:32:35
国产数据库需要扩大场景覆盖面才能在竞争中更有优势
白鳝的洞穴
564次阅读
2025-04-14 09:40:20
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
491次阅读
2025-04-17 17:02:24
一页概览:Oracle GoldenGate
甲骨文云技术
468次阅读
2025-04-30 12:17:56
GoldenDB数据库v7.2焕新发布,助力全行业数据库平滑替代
GoldenDB分布式数据库
459次阅读
2025-04-30 12:17:50