數據庫遷移expdp impdp 與 OGg 搭建
1.long 字段的無法使用OGG 同步
2.clob字段的導入導出Bug , 生產使用network-link 導入導出太慢了,本地導入導出速度會快3到4倍 。但是測試環境的情況卻相反
測試環境和生產環境測試結果如下: 最後還是以生產環境的數據為主。
原因有2點,第一 : 測試環境的網絡沒有擁塞,所以感覺測試環境network-link I/O 速度可以接受。第二測試環境的I/O 太慢了,跟生產環境不是一個等量級,所以感覺生產環境 本地I/O 會快很多。
數據局遷移遇到的Bug
1.DRAFT_LOG 這個表有6G ,有clob 字段
2._LOG 這張表因為有clob 字段,這張表是核心表,導出時間和導入時間會有比較長。大概有19G ,
因為有clob 字段,導出時間會比較長。根據我們測試,
測試1:(測試環境),不使用network_link 方式,
EXPDP 這2張表時間會達到3個小時。
IMPDP 這2張表時間也會超過3個小時。
測試2: (測試環境) ,使用network_link 方式,
時間會縮短一倍,達到3個半小時。
測試3:(生產環境),使用network_link 方式,
從上午11點25發起,持續到16點,已經跑了4個半小時,還在導入。
測試4: (生產環境) ,使用本地導入導出方式,不使用network_link 方式,除去BAK_RGCT_DRAFT_LOG這個6G表。
EXPDP 所有生產用戶時間會達到1個小時10分鐘。
IMPDP 所有生產用戶時間會達到1個小時10分鐘。
可以在2個半小時左右完成,
1.
檢查項 "1.創建空庫不需要初始化
2.檢查生產的FRA空間檢查
生產的在維護期間會創建一個回滾點並保留7天,所以要檢查災備FRA的卷空間是否能保留7天的日誌量。不足需申請擴空間。"
新建目標空庫 "1,只包含system,sysaux,undotbs1,temp,users 表空間,不需要初始化。
set line 200 pagesize 200
select tablespace_name from dba_tablespaces a
where (a.tablespace_name not in (‘TEMP‘,‘SYSAUX‘,‘SYSTEM‘,‘USERS‘)
and a.contents not in (‘TEMPORARY‘,‘UNDO‘)) ;
2,字符集、block size與源庫保持一致
select * from v$nls_parameters where parameter=‘NLS_CHARACTERSET‘;
show parameter block_size;
3,安裝組件和源生產一致。
select comp_name,version,status from dba_registry order by 1;
4.源庫和目標庫具有相同的timeone;
SELECT VERSION FROM V$TIMEZONE_FILE;
8.db_cache_size
設置為和源庫相同
show parameter db_cache_size
9.註:9.1.目標庫cpu_count 不要在spfile裏進行設置,不需要和源庫保持一致
9.2.目標庫的parallel_max_servers設置要和源庫一致。
10.job_queue_processes,aq_tm_processes 設置為0。
11.修改新建的目標庫為非歸檔模式
12,11g數據庫參數按標準新建庫手冊。
13. 關閉Flashback。
select flashback_on from v$database; --結果為NO
15.awr配置為間隔15分鐘,保留90天
exec dbms_workload_repository.modify_snapshot_settings(interval=>15, retention=>90*24*60);
col SNAP_INTERVAL format a20
col RETENTION format a20
select * from dba_hist_wr_control;"
檢查遷移對象是否是閉包的 "1:檢查遷移用戶引用非遷移用戶的對象,如果引用的是系統表酌情處理;如果引用的是非系統表則要整改。
select * from dba_dependencies dd where dd.owner in
(‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) --替換為實際用戶
and dd.referenced_owner not in
(‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘)
2:檢查非遷移用戶引用遷移用戶的對象,如果存在則與開發討論處理方法。
select * from dba_dependencies dd where dd.type<>‘SYNONYM‘ and dd.owner not in
(‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) ----替換為實際用戶
and dd.referenced_owner in
(‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) ----替換為實際用戶
/"
檢查遷移schema的trigger是否是閉包的 "1:檢查觸發器的owner<>table_owner且owner不在遷移用戶列表而table_owner在遷移用戶列表的情況,這種觸發器需要手工遷移
select * from dba_triggers where owner<>table_owner and owner not in (‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) and table_owner in (‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) ;
2:檢查觸發器的owner<>table_owner且owner在遷移用戶列表而table_owner不在遷移用戶列表的情況,這種觸發器視情況決定是否遷移
select * from dba_triggers where owner<>table_owner and owner not in (‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) and table_owner in (‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) ;
3:檢查觸發器的triggering_eventowner‘LOGON ‘且owner在遷移用戶列表或table_owner在遷移用戶列表的情況,這種觸發器expdp不能導出需要手工遷移
select * from dba_triggers where triggering_event=‘LOGON ‘and (owner in (‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘) or table_owner in (‘BBSP‘,‘BBSPODS‘,‘BCDPETL‘,‘DBMONOPR‘,‘DBMGR‘,‘OVSEE‘));
"
根據10g生產庫中待遷移job清單信息,生成job遷移腳本並在測試環境驗證通過。特別註意:腳本所有待遷移job其next_date都必須設為無限大。 t_update_status();
檢查10g生產庫中是否有業務scheduler存在,這些scheduler也要進行遷移,如果存在有,本步要把遷移scheduler的腳本準備好 0
"
創建11g目標庫到10g生產庫的dblink" "create public database link dblink_migup connect to dbmgr identified by &pw
using ‘ 生產庫連接串 ‘;
3:驗證dblink是否通
select * from dual@dblink_migup; --有結果返回表示通的否則不通需處理
"
"
1. 創建要遷移的用戶清單配置表(sys..t_user_cfg)
" "create table sys.t_user_cfg as SELECT username, default_tablespace
FROM dba_users@dblink_migup
WHERE username not in
(‘SYS‘, ‘SYSTEM‘, ‘PUBLIC‘, ‘OUTLN‘, ‘WMSYS‘, ‘ORDSYS‘, ‘MDSYS‘,
‘CTXSYS‘, ‘XDB‘, ‘WKSYS‘, ‘ANONYMOUS‘, ‘ORDPLUGINS‘, ‘EXFSYS‘,
‘LBACSYS‘, ‘DIP‘, ‘LBACSYS‘, ‘ORACLE_OCM‘, ‘TSMSYS‘, ‘ADAMS‘,
‘TRACESVR‘, ‘DBSNMP‘, ‘PERFSTAT‘, ‘DBSTATS‘, ‘EXPFULL‘,
‘MDDATA‘, ‘MGMT_VIEW‘, ‘OLAPSYS‘, ‘SI_INFORMTN_SCHEMA‘, ‘OWBSYS‘,
‘SYSMAN‘, ‘ORDDATA‘, ‘OWBSYS_AUDIT‘, ‘APEX_030200‘, ‘APPQOSSYS‘,
‘MDSYS‘, ‘FLOWS_FILES‘, ‘SPATIAL_WFS_ADMIN_USR‘,
‘SPATIAL_CSW_ADMIN_USR‘, ‘APEX_PUBLIC_USER‘, ‘XS$NULL‘,‘DMSYS‘)
minus
select username, default_tablespace from dba_users;"
目標端新增表空間 "1.查看源庫表空間名稱及大小,在目標庫新建相同大小表空間
set line 200 pagesize 200
select tablespace_name from dba_tablespaces a
where a.tablespace_name not in (‘TEMP‘,‘SYSAUX‘,‘SYSTEM‘,‘USERS‘) ;
--註意臨時表空間是否有特殊的,CREATE TEMPORARY TABLESPACE RLMSTMP TEMPFILE ‘+DATA_HDG‘ SIZE 100M AUTOEXTEND ON;
2.打開所有表空間的自動擴展
select ‘alter database datafile ‘‘‘||file_name||‘‘‘ autoextend on next 100M;‘ from dba_data_files ;
select ‘alter database tempfile ‘‘‘||file_name||‘‘‘ autoextend on next 100M;‘ from dba_temp_files ;
執行上面生成的腳本
復核:
select df.tablespace_name,df.autoextensible from dba_temp_files df where df.autoextensible=‘NO‘;
select df.tablespace_name,df.autoextensible from dba_data_files df where df.autoextensible=‘NO‘;"
目標端創建role "SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/01_create_role.sql
select ‘create role ‘ || role || ‘;‘
from (select role
from dba_roles@dblink_migup
minus
select role from dba_roles);
spool off;
在目標庫執行01_create_role.sql"
創建密碼函數 "執行附件腳本創建密碼函數sys.VERIFY_FUNCTION_11G
PS:這個密碼函數如果老庫的名稱不一樣,需要把老庫的函數遷移過來。"
創建profile "SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/02_deal_profile.sql
select (case
when rn = 1 then
(‘create profile ‘ || profile ||‘ limit ‘ || resource_name ||‘ ‘ || limit || (case
when rn = max_rn then
‘;‘
end)) else(resource_name || ‘ ‘ || limit || (case
when rn = max_rn then
‘;‘
end)) end)
from (select profile,
resource_name,
limit,
row_number() over(partition by profile order by profile, resource_name) rn,
count(*) over(partition by profile) max_rn
from dba_profiles@dblink_migup
where profile in
(select distinct profile
from dba_profiles@dblink_migup
minus
select distinct profile from dba_profiles)
order by profile, resource_name)
order by profile, resource_name;
spool off;
執行02_deal_profile.sql
alter profile default limit PASSWORD_VERIFY_FUNCTION VERIFY_FUNCTION_11G;
alter profile default limit FAILED_LOGIN_ATTEMPTS 10;
復核:
select * from dba_profiles minus select * from dba_profiles@dblink_migup;
select * from dba_profiles@dblink_migup minus select * from dba_profiles;"
創建公共同義詞 "SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/03_create_public_synonym.sql
SELECT
‘create or replace public synonym ‘||synonym_name||‘ for ‘||table_owner||‘.‘||table_name||‘;‘
FROM dba_synonyms@dblink_migup
WHERE owner = ‘PUBLIC‘
AND table_owner IN ( select username from sys.t_user_cfg t) ;
spool off;
在目標庫執行03_create_public_synonym.sql"
移植cron "
將原hp平臺上的crontab移植到新linux主機上。
"
2.
21:00 導出BBSP.RGCT_DRAFT_LOG "export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
cd /db/db1/oradata/dba/exp_table
vi expdp_rgct_log.par
userid=‘/ as sysdba‘
directory=schema_exp
dumpfile=expdp_rgct_log_%U.dmp
logfile=expdp_rgct_draft_log.log
parallel=4
filesize=10240M
tables=(BBSP.RGCT_DRAFT_LOG)
content=all "
22:00 scp傳輸到linux scp *.dmp [email protected]:/db/db1/app/opdb1/db1_impdp
22:00 新庫創建用戶 "create user bbsp identified by values ‘DF01EB216CE6E6BE‘ default tablespace bbsp profile default;
grant unlimited tablespace to bbsp;
alter user bbsp quota unlimited on users;
alter user bbsp quota unlimited on bbsp;
"
22:10 導入BBSP.RGCT_DRAFT_LOG "chown -R opdb1:dba /db/db1/app/opdb1/db1_impdp/*.dmp
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
cd /db/db1/app/opdb1/db1_impdp
vi impdp_rgct_log.par
userid=‘/ as sysdba‘
directory=schema_imp
dumpfile=expdp_rgct_log_%U.dmp
logfile=impdp_rgct_draft_log.log
parallel=4
tables=(BBSP.RGCT_DRAFT_LOG)
content=all
nohup impdp parfile=impdp_rgct_log.par &
檢查導出導入日誌是否有報錯"
T-0 "DBA檢查DB中的long oper、
rbs占用,
並請運營確認和做相應處理" "sqlplus ‘/ as sysdba‘
alter system switch logfile ;
alter system switch logfile ;
alter system switch logfile ;
alter system archive log current;
1)檢查long operation
select sid, target,opname, sofar,totalwork,time_remaining
from gv$session_longops where time_remaining>0;
2)檢查占用回滾段較多的事務:
select xidusn,s.last_call_et, s.username, used_ublk,USED_UREC,space,
RECURSIVE, NOUNDO, START_UBAFIL,start_ubablk, start_uext
from gv$transaction t, gv$session s
where t.ses_addr=s.saddr;
"
1:00 維護時間開始處理,通知應用停止應用 應用將庫的所有相關應用系統和job、ETL任務等停止下來。
T-0 檢查卷,凍結源庫雙機軟件 "凍結源庫的雙機,
凍結目標庫的雙機"
T-0 全備,磁帶永久保留
T-0 DBA停止報警,屏蔽cron "cd $HOME
touch cron_null
crontab cron_null
crontab -l 返回值應該為空"
T-0 修改端口 "lsnrctl stop db1
修改監聽端口為1537
cd $ORACLE_HOME/network/admin
vi listener.ora
lsnrctl start db1"
T-0 重建到舊庫的db links。 "1:在目標庫重建遷移用的臨時dblink ---直接使用連接串
drop public database link dblink_migup;
create public database link dblink_migup connect to dbmgr identified by db1234DBA
using ‘ (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =10.198.69.10)(PORT = 1537)) (CONNECT_DATA =(sid = db1)))‘;
2:驗證dblink是否通
select * from dual@dblink_migup; --有結果返回表示通的否則不通需處理"
T-0 修改job_queue_processes,aq_tm_processes為0,關閉audit "保留記錄job_queue_processes及aq_tm_processes修改前的值。
show parameter job_queue_processes --- 1000
show parameter aq_tm_processes ---1
alter system set job_queue_processes=0 scope=both;
alter system set aq_tm_processes=0 scope=both;
alter system set audit_trail=none scope=spfile;"
T-0 "DBA檢查DB中的long oper、
rbs占用,
並請運營確認和做相應處理" "sqlplus ‘/ as sysdba‘
alter system switch logfile ;
alter system switch logfile ;
alter system switch logfile ;
alter system archive log current;
1)檢查long operation
select sid, target,opname, sofar,totalwork,time_remaining
from gv$session_longops where time_remaining>0;
2)檢查占用回滾段較多的事務:
select xidusn,s.last_call_et, s.username, used_ublk,USED_UREC,space,
RECURSIVE, NOUNDO, START_UBAFIL,start_ubablk, start_uext
from gv$transaction t, gv$session s
where t.ses_addr=s.saddr;
"
T-0 修改stream_pool_size alter system set streams_pool_size=128M scope=both;
T-0 1.設置JOB的next_date為無限大 "備份原庫的Job:create table dbmgr.dbajobs_old_bak as select * from dba_jobs;
復核:SELECT COUNT(*) FROM dbmgr.dbajobs_old_bak;
設置JOB的next_date為無限大:"
T-0 原庫創建用戶清單表sys.t_user_list "create table sys.t_user_cfg as SELECT username, default_tablespace
FROM dba_users
WHERE username not in
(‘SYS‘, ‘SYSTEM‘, ‘PUBLIC‘, ‘OUTLN‘, ‘WMSYS‘, ‘ORDSYS‘, ‘MDSYS‘,
‘CTXSYS‘, ‘XDB‘, ‘WKSYS‘, ‘ANONYMOUS‘, ‘ORDPLUGINS‘, ‘EXFSYS‘,
‘LBACSYS‘, ‘DIP‘, ‘LBACSYS‘, ‘ORACLE_OCM‘, ‘TSMSYS‘, ‘ADAMS‘,
‘TRACESVR‘, ‘DBSNMP‘, ‘PERFSTAT‘, ‘DBSTATS‘, ‘EXPFULL‘,
‘MDDATA‘, ‘MGMT_VIEW‘, ‘OLAPSYS‘, ‘SI_INFORMTN_SCHEMA‘, ‘OWBSYS‘,
‘SYSMAN‘, ‘ORDDATA‘, ‘OWBSYS_AUDIT‘, ‘APEX_030200‘, ‘APPQOSSYS‘,
‘MDSYS‘, ‘FLOWS_FILES‘, ‘SPATIAL_WFS_ADMIN_USR‘,
‘SPATIAL_CSW_ADMIN_USR‘, ‘APEX_PUBLIC_USER‘, ‘XS$NULL‘,‘DMSYS‘);
grant select on sys.t_user_cfg to public;"
T-0 部署數據比對的procedure "grant select on dba_tab_columns to dbmgr;
create table dbmgr.TAB_HASH
(
OWNER VARCHAR2(30),
TABLE_NAME VARCHAR2(50),
SQL_VALUE VARCHAR2(4000),
HASH_VALUE NUMBER(20)
) ;
CREATE OR REPLACE PROCEDURE DBMGR.GET_TAB_HASH8(V_OWNER VARCHAR2,
V_TABLE_NAME VARCHAR2) AS
v_sql_temp varchar2(4000);
v_hash number(20);
BEGIN
FOR r in (SELECT COLUMN_NAME
FROM DBA_TAB_COLUMNS
WHERE OWNER = V_OWNER
AND TABLE_NAME = V_TABLE_NAME
AND DATA_TYPE NOT IN (‘CLOB‘, ‘BLOB‘)
and OWNER IN (SELECT USERNAME FROM sys.t_user_cfg)
order by 1 asc) loop
v_sql_temp := v_sql_temp || ‘||‘ || R.COLUMN_NAME;
end loop;
v_sql_temp := ‘select/*+ parallel(t 8) full(t)*/ sum(dbms_utility.get_hash_value(‘ ||
substr(v_sql_temp, 3) || ‘, 0, 999999999)) from ‘ ||
V_OWNER || ‘.‘ || V_TABLE_NAME || ‘ t‘;
execute immediate v_sql_temp
into v_hash;
insert into tab_hash
(owner, table_name, sql_value, hash_value)
values
(V_OWNER, V_TABLE_NAME, v_sql_temp || ‘;‘, v_hash);
commit;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
/"
T-0 為GG回滾庫做的disable/enable trigger以及constraint腳本。 "set linesize 300
SPOOL $HOME/disable_constraint_r.sql
SELECT ‘spool ./disable_constraint_r.log‘ FROM dual;
SELECT ‘alter table ‘||owner||‘.‘||table_name||‘ disable constraint ‘||constraint_name||‘;‘
FROM dba_constraints
WHERE owner IN (select username from sys.t_user_cfg)
AND constraint_type = ‘R‘
ORDER BY constraint_type desc, owner, table_name, constraint_name;
SELECT ‘spool off‘ FROM dual;
SPOOL OFF
SPOOL ./disable_trigger.sql
SELECT ‘spool ./disable_trigger.log‘ FROM dual;
SELECT
‘alter trigger ‘||owner||‘.‘||trigger_name||‘ disable;‘
FROM dba_triggers
WHERE owner IN (select username from sys.t_user_cfg)
AND status <> ‘DISABLED‘
ORDER BY owner, table_name, trigger_name;
SELECT ‘spool off‘ FROM dual;
SPOOL OFF
SPOOL ./enable_trigger.sql
SELECT ‘spool ./enable_trigger.log‘ FROM dual;
SELECT
‘alter trigger ‘||owner||‘.‘||trigger_name||‘ enable;‘
FROM dba_triggers
WHERE owner IN (select username from sys.t_user_cfg)
AND status = ‘ENABLED‘
ORDER BY owner, table_name, trigger_name;
SELECT ‘spool off‘ FROM dual;
SPOOL OFF
SPOOL ./enable_constraint_r_novalidate.sql
SELECT ‘spool ./enable_constraint_r_novalidate.log‘ FROM dual;
SELECT
‘alter table ‘||owner||‘.‘||table_name||‘ modify constraint ‘||constraint_name||‘ enable novalidate;‘
FROM dba_constraints
WHERE owner IN (select distinct username from sys.t_user_cfg)
AND constraint_type = ‘R‘
AND STATUS = ‘ENABLED‘
ORDER BY constraint_type desc, owner, table_name, constraint_name;
SELECT ‘spool off‘ FROM dual;
SPOOL OFF
SPOOL ./enable_constraint_src_r.sql
SELECT ‘spool ./enable_constraint_src_r.log‘ FROM dual;
SELECT
‘alter table ‘||owner||‘.‘||table_name||‘ modify constraint ‘||constraint_name||‘ enable novalidate;‘
FROM dba_constraints
WHERE owner IN (select distinct username from sys.t_user_cfg)
AND constraint_type = ‘R‘
AND status = ‘ENABLED‘
ORDER BY constraint_type desc, owner, table_name, constraint_name;
SELECT ‘spool off‘ FROM dual;
SPOOL OFF"
T-0 重啟生產庫 "
shutdown immediate;
startup
"
T-0 停止同城災備db 沒有災備庫
T-0 清空回收站 Purge dba_recyclebin;
T-0 expdp導出 "export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
connect / as sysdba
create or replace directory schema_exp as ‘/db/db1/oradata/expdp_db1‘;
cd /db/db1/oradata/expdp_db1
userid=‘/ as sysdba‘
directory=schema_exp
dumpfile=expdp_schemas_%U.dmp
logfile=expdp_schemas.log
parallel=6
filesize=10240M
schemas=BBSP,BBSPODS,BCDPETL,DBMONOPR
content=all
EXCLUDE=TABLE:""in (‘BAK_RGCT_DRAFT_LOG‘,‘RGCT_DRAFT_LOG‘)""
nohup expdp parfile=expdp.par &"
檢查error more expdp_schemas.log |grep -i error
T-0 impdp導入 "scp *.dmp [email protected]:/db/db1/app/opdb1/db1_impdp
chown -R opdb1:dba /db/db1/app/opdb1/db1_impdp/*.dmp
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
userid=‘/ as sysdba‘
directory=schema_imp
dumpfile=expdp_schemas_%U.dmp
logfile=impdp_schemas.log
parallel=6
schemas=BBSP,BBSPODS,BCDPETL,DBMONOPR
content=all
nohup impdp parfile=impdp.par &"
T-0 檢查error more impdp_schemas.log |grep -i error
T-0 grant GRANT SELECT ON "BBSP"."RGCT_DRAFT_LOG" TO "BCDPETL"
T-0 查出時點ID記錄數最大的做保存 select max(l.id) from bbsp.rgct_draft_log l
T-0 用記錄的最大id查出新增數據 select count(*) from bbsp.rgct_draft_log l where l.id>xxxxx; --替換為上一步查出的值
T-0 補錄新增數據到bbsp.rgct_draft_log "insert into bbsp.rgct_draft_log select * from bbsp.rgct_draft_log@dblink_migup where id>xxxxxxxx ;
commit;"
T-0 "數據核對
並且點開lob字段查詢是否有值" "select count(*) from bbsp.rgct_draft_log ;
select * from bbsp.rgct_draft_log ;"
T-0 清除impdp導到目標庫sys用戶下的job並復核 "select * from dba_jobs;
清除impdp導到sys用戶下的job
DECLARE X NUMBER;
BEGIN
for cur in ( select * from dba_jobs j where j.log_user = ‘SYS‘) loop
SYS.DBMS_iJOB.remove(job => cur.job );
COMMIT;
end loop ;
commit;
END;
/"
T-1 創建公共同義詞 "SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/03_create_public_synonym.sql
SELECT
‘create or replace public synonym ‘||synonym_name||‘ for ‘||table_owner||‘.‘||table_name||‘;‘
FROM dba_synonyms@dblink_migup
WHERE owner = ‘PUBLIC‘
AND table_owner IN ( select username from sys.t_user_cfg t) ;
spool off;
在目標庫執行03_create_public_synonym.sql"
T-0 生成用戶審計信息 "SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/04_audit_users.sql
SELECT
‘audit connect by ‘||user_name||‘;‘
FROM dba_stmt_audit_opts@dblink_migup
WHERE audit_option = ‘CREATE SESSION‘
and user_name in ( select username from sys.t_user_cfg )
and user_name is not null;
SELECT
‘audit ‘||audit_option||‘ by ‘||user_name||‘ by session whenever successful;‘
FROM dba_stmt_audit_opts@dblink_migup
WHERE audit_option <> ‘CREATE SESSION‘
and user_name in ( select username from sys.t_user_cfg )
and user_name is not null;
SPOOL OFF;"
T-0 添加用戶審計信息 執行04_audit_user.sql
T-0 給用戶和角色授權 "1.執行附件腳本04_grant.sql
2.可以看到生成的腳本$HOME/grant_role_priv.sql,$HOME/grant_sys_priv.sql,$HOME/grant_sys_tab_priv.sql
3.檢查沒問題後執行上面生成的3個腳本"
T-0 目標庫編譯失效對象 sqlplus> @?/rdbms/admin/utlrp.sql;
T-0 對比源庫和目標庫確保無新增失效對象 "select owner ,object_name, status from dba_objects where status = ‘INVALID‘
minus
select owner ,object_name, status from dba_objects@dblink_migup where status = ‘INVALID‘;"
T-0 檢查表和索引的統計信息是否被鎖住 "select owner,table_name,partition_name,t.stattype_locked from dba_tab_statistics t where t.stattype_locked is not null and t.owner in (select username from sys.t_user_cfg);
select owner,index_name,table_owner,table_name,partition_name,stattype_locked from dba_ind_statistics t where t.stattype_locked is not null and t.owner in (select username from sys.t_user_cfg);
如果有結果,說明有表或索引統計信息被鎖定
執行下列拼出來的語句
select case when partition_name is null then ‘exec dbms_stats.unlock_table_stats(ownname =>‘‘‘ ||owner || ‘‘‘,tabname =>‘‘‘ || table_name || ‘‘‘);‘
else ‘exec dbms_stats.unlock_table_stats(ownname =>‘‘‘ ||owner || ‘‘‘,tabname =>‘‘‘ || table_name ||‘‘‘,partname =>‘‘‘|| partition_name||‘‘‘);‘ end
from dba_tab_statistics t
where t.stattype_locked is not null
and t.owner in (select username from sys.t_user_cfg);
select case when partition_name is null then ‘exec dbms_stats.unlock_table_stats(ownname =>‘‘‘ ||table_owner || ‘‘‘,tabname =>‘‘‘ || table_name || ‘‘‘);‘
else ‘exec dbms_stats.unlock_table_stats(ownname =>‘‘‘ ||table_owner || ‘‘‘,tabname =>‘‘‘ || table_name ||‘‘‘,partname =>‘‘‘|| partition_name||‘‘‘);‘ end
from dba_ind_statistics t where t.stattype_locked is not null and t.owner in (select username from sys.t_user_cfg);"
T-0 "復核以下項在源和目標環境中是否相等
" " 檢查遷移用戶系統權限
檢查遷移用戶角色權限
檢查遷移用戶對象權限
檢查遷移用戶審計
檢查遷移用戶對象同義詞
檢查遷移用戶db_link
檢查遷移用戶context
檢查遷移用戶的對象總數
遷移用戶的constraint
檢查遷移用戶的index(含索引字段)
檢查遷移用戶的表結構
遷移用戶的trigger
檢查遷移用戶的表記錄數
檢查遷移用戶的seq數及last_number"
T-0 核心表數據比對 "select count(*)登記中心數 from BBSP.rgct_bill_info
union
select count(*)登記中心歷史數 from BBSP.rgct_bill_hist
T-0 打開歸檔 "shutdown immediate;
startup nomount;
alter database mount;
alter database archivelog;
alter database open;"
T-0 關閉undo和temp表空間的自動擴展 "select ‘alter database datafile ‘‘‘||file_name||‘‘‘ autoextend off;‘ from dba_data_files where tablespace_name like ‘UNDO%‘;
select ‘alter database tempfile ‘‘‘||file_name||‘‘‘ autoextend off;‘ from dba_temp_files ;
執行產出腳本"
T-0 復核job參數 "檢查Job參數設置,設置為0
SQL> show parameter job_queue_processes --0
SQL> show parameter aq_tm_processes --0"
force logging開啟 alter database force logging;
T-0 gg混滾鏈路處理 "alter table BBSP.CODE logging;
alter table BBSP.PRODUCT logging;
"
T-0 gg鏈路處理 按gg回滾手冊進行部署
T-0 配置監聽 "【新庫恢復監聽】
lsnrctl stop db1
並修改監聽端口為1528
cd $ORACLE_HOME/network/admin
vi listener.ora
lsnrctl start db1 --監聽端口是1528"
T-0 DNS切換,清理緩存 找應用值班同事執行
T-0 驗證連通性 sqlplus客戶端驗證
T-0 啟動中間件和相關應用
T-0 通知開發、應用驗證應用
T-0 打開Job參數 "SQL> alter system set job_queue_processes = 1000 scope = both;
SQL> alter system set aq_tm_processes=1 scope = both;;
復核:
SQL> show parameter job_queue_processes
SQL> show parameter aq_tm_processes
"
T-0 恢復cron文件 無
T-0 註冊catalog "Rman註冊:
步驟如下(主庫):
shell>rman target / catalog rman11g/rman11g@cat11g
RMAN> register database;
RMAN> report schema;
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 90 DAYS;
RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO BACKED UP 1 TIMES TO ‘SBT_TAPE‘;
RMAN>show all;"
2.1 set_job_nextdate.sql
SET termout on feedback on verify OFF echo on heading OFF trims ON escape ON pages 0 linesize 999 long 3000
set SERVEROUTPUT on size 200000
alter session set nls_date_format=‘yyyy/mm/dd hh24:mi:ss‘ ;
begin
for cur in ( select * from dba_jobs j where j.BROKEN = ‘N‘ ) loop
sys.dbms_ijob.next_date(job => cur.job,next_date=>to_date(‘2999/9/9‘,‘yyyy/mm/dd‘)) ;
end loop ;
commit ;
end;
/
select count(1) from dba_jobs j where j.next_date < to_date(‘2999-09-09‘,‘yyyy-mm-dd‘) and j.broken = ‘N‘;
2.2 04_grant.sql
SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/grant_role_priv.sql
SELECT ‘spool $HOME/grant_role_priv.log‘ FROM dual;
SELECT ‘grant ‘ || granted_role || ‘ to ‘ || grantee || CASE admin_option
WHEN ‘YES‘ THEN
‘ with admin option;‘
ELSE
‘;‘
END
FROM dba_role_privs@dblink_migup
WHERE grantee IN
( select username from sys.t_user_cfg
union
select distinct granted_role from dba_role_privs@dblink_migup WHERE grantee IN (select username from sys.t_user_cfg)
and granted_role like ‘R\_%‘ escape ‘\‘
) ;
SELECT ‘spool off;‘ FROM dual;
SPOOL OFF;
commit;
SET termout on echo on
--SET termout OFF feedback on verify OFF echo on heading OFF trims ON escape ON pages 0 linesize 999 long 3000
--@$HOME/grant_role_priv.sql
--commit;
SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/grant_sys_priv.sql
SELECT ‘spool $HOME/grant_sys_priv.log‘ FROM dual;
SELECT
‘grant ‘||privilege||‘ to ‘||grantee
||CASE admin_option WHEN ‘YES‘ THEN ‘ with admin option;‘ ELSE ‘;‘ END
FROM dba_sys_privs@dblink_migup
WHERE grantee IN
( select username from sys.t_user_cfg
union
select distinct granted_role from dba_role_privs@dblink_migup WHERE grantee IN (select username from sys.t_user_cfg)
and granted_role like ‘R\_%‘ escape ‘\‘
) ;
SELECT
‘grant ‘||privilege||‘ to ‘||grantee
||CASE admin_option WHEN ‘YES‘ THEN ‘ with admin option;‘ ELSE ‘;‘ END
FROM dba_sys_privs@dblink_migup
WHERE grantee IN (SELECT role FROM dba_roles WHERE password_required <> ‘NO‘ AND ROLE LIKE ‘R\_%‘ ESCAPE ‘\‘);
SELECT ‘spool off;‘ FROM dual;
SPOOL OFF;
commit;
SET termout on echo on
--SET termout OFF feedback on verify OFF echo on heading OFF trims ON escape ON pages 0 linesize 999 long 3000
--@$HOME/grant_sys_priv.sql
--commit;
SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
spool $HOME/grant_sys_tab_priv.sql
SELECT ‘spool $HOME/grant_sys_tab_priv.log‘ FROM dual;
SELECT
‘grant ‘||privilege||‘ on ‘
||CASE WHEN substr(table_name,1,2)=‘V$‘ THEN ‘V_$‘||substr(table_name,3,length(table_name-2)) ELSE table_name END
||‘ to ‘||grantee||CASE grantable WHEN ‘YES‘ THEN ‘ with grant option;‘ ELSE ‘;‘ END
FROM dba_tab_privs@dblink_migup
WHERE grantee IN
( select username from sys.t_user_cfg
union
select distinct granted_role from dba_role_privs@dblink_migup WHERE grantee IN (select username from sys.t_user_cfg)
and granted_role like ‘R\_%‘ escape ‘\‘
)
AND owner = ‘SYS‘
and table_name NOT in(‘EXPDIR‘,‘V_$TEMP_HISTOGRAM‘,‘V_$STANDBY_APPLY_SNAPSHOT‘,‘GV_$TEMP_HISTOGRAM‘,‘GV_$STANDBY_APPLY_SNAPSHOT‘ ,‘DBA_ADVISOR_DIRECTIVES‘,‘DBA_CACHEABLE_TABLES‘ , ‘DBA_CACHEABLE_OBJECTS_BASE‘ , ‘DBA_CACHEABLE_OBJECTS‘ ,‘DBA_USERS2‘) -----opms Special
AND privilege NOT IN (‘READ‘,‘WRITE‘);
SELECT
‘grant ‘||privilege||‘ on directory ‘||table_name||‘ to ‘||grantee
||CASE grantable WHEN ‘YES‘ THEN ‘ with grant option;‘ ELSE ‘;‘ END
FROM dba_tab_privs@dblink_migup
WHERE grantee IN
( select username from sys.t_user_cfg
union
select distinct granted_role from dba_role_privs@dblink_migup WHERE grantee IN (select username from sys.t_user_cfg)
and granted_role like ‘R\_%‘ escape ‘\‘
)
AND owner = ‘SYS‘
AND privilege IN (‘READ‘, ‘WRITE‘)
AND table_name not in ( ‘EXPDIR‘ );
SELECT ‘spool off;‘ FROM dual;
SPOOL OFF;
commit;
SET termout on echo on
--SET termout OFF feedback on verify OFF echo on heading OFF trims ON escape ON pages 0 linesize 999 long 3000
--@$HOME/grant_sys_tab_priv.sql
--commit;
2.3 check.sql
----check object -----------------
--CHECK OBJECT
select owner,object_name,object_type,status
from dba_objects@dblink_migup
where owner in (select username from sys.t_user_cfg)
and status <> ‘INVALID‘
And (owner,object_name) Not In (Select owner,segment_name From dba_lobs@dblink_migup
Union All Select owner,index_name From dba_lobs@dblink_migup)
minus
select owner,object_name,object_type,status
from dba_objects
where owner in (select username from sys.t_user_cfg)
and status <> ‘INVALID‘
And (owner,object_name) Not In (Select owner,segment_name From dba_lobs Union All Select owner,index_name From dba_lobs);
----check system priv-------------
select grantee,privilege from dba_sys_privs@dblink_migup
where grantee in ( select username from sys.t_user_cfg)
minus
select grantee,privilege from dba_sys_privs
where grantee in ( select username from sys.t_user_cfg) ;
----check role priv-------------
select grantee,granted_role,admin_option from dba_role_privs@dblink_migup
where grantee in ( select username from sys.t_user_cfg)
minus
select grantee,granted_role,admin_option from dba_role_privs
where grantee in ( select username from sys.t_user_cfg) ;
---check role----
select role from dba_roles@dblink_migup
minus
select role from dba_roles;
--CHECK SYS PRIVS
select grantee,privilege,admin_option
from dba_sys_privs@dblink_migup
where grantee in (select username from sys.t_user_cfg)
minus
select grantee,privilege,admin_option
from dba_sys_privs
where grantee in (select username from sys.t_user_cfg) ;
--CHECK ROLE PRIVS
select grantee,granted_role,admin_option
from dba_role_privs@dblink_migup
where grantee in (select username from sys.t_user_cfg)
minus
select grantee,granted_role,admin_option
from dba_role_privs
where grantee in (select username from sys.t_user_cfg) ;
----check user object priv-------------
select grantee,owner,table_name,grantor,privilege,grantable from dba_tab_privs@dblink_migup
where grantee in ( select username from sys.t_user_cfg)
minus
select grantee,owner,table_name,grantor,privilege,grantable from dba_tab_privs
where grantee in ( select username from sys.t_user_cfg) ;
-----check quota---------------
select username,max_bytes
from dba_ts_quotas@dblink_migup
where username in (select username from sys.t_user_cfg)
minus
select username,max_bytes
from dba_ts_quotas
where username in (select username from sys.t_user_cfg) ;
--check audit-------------
select user_name,audit_option,success,failure
from dba_stmt_audit_opts@dblink_migup
where user_name in ( select username from sys.t_user_cfg)
minus
select user_name,audit_option,success,failure
from dba_stmt_audit_opts
where user_name in ( select username from sys.t_user_cfg) ;
--check synonym no rows selected
select owner,synonym_name,table_owner,table_name
from dba_synonyms@dblink_migup
where table_owner in ( select username from sys.t_user_cfg)
minus
select owner,synonym_name,table_owner,table_name
from dba_synonyms
where table_owner in ( select username from sys.t_user_cfg) ;
--check db links no rows selected
select owner,db_link,username,host from dba_db_links@dblink_migup
where owner in ( select username from sys.t_user_cfg)
minus
select owner,db_link,username,host from dba_db_links
where owner in ( select username from sys.t_user_cfg) ;
--check db context no rows selected
select namespace,schema,package,type
from dba_context@dblink_migup
where schema in ( select username from sys.t_user_cfg)
minus
select namespace,schema,package,type
from dba_context
where schema in ( select username from sys.t_user_cfg) ;
--CHECK OBJECT COUNT
select owner,object_type,status,count(*)
from dba_objects@dblink_migup
where owner in (select username from sys.t_user_cfg)
And (owner,object_name) Not In (Select owner,segment_name From dba_lobs@dblink_migup
Union All Select owner,index_name From dba_lobs@dblink_migup)
group by owner,object_type,status
minus
select owner,object_type,status,count(*)
from dba_objects
where owner in (select username from sys.t_user_cfg)
And (owner,object_name) Not In (Select owner,segment_name From dba_lobs Union All Select owner,index_name From dba_lobs)
group by owner,object_type,status;
--check table no rows selected
select owner,table_name,partitioned,iot_type,temporary
from dba_tables@dblink_migup
where owner in ( select username from sys.t_user_cfg)
minus
select owner,table_name,partitioned,iot_type,temporary
from dba_tables
where owner in ( select username from sys.t_user_cfg) ;
--check constraint no rows selected
select owner, constraint_name, constraint_type, table_name, r_owner, status
from dba_constraints@dblink_migup
where owner in (select username from sys.t_user_cfg)
and constraint_name not like ‘SYS%‘ and constraint_name not like ‘BIN$%‘
minus
select owner, constraint_name, constraint_type, table_name, r_owner, status
from dba_constraints
where owner in (select username from sys.t_user_cfg)
and constraint_name not like ‘SYS%‘ and constraint_name not like ‘BIN$%‘;
------check index---------------------
select index_owner,index_name,table_owner,table_name,column_name,column_position
from dba_ind_columns@dblink_migup
where table_owner in (select username from sys.t_user_cfg)
minus
select index_owner,index_name,table_owner,table_name,column_name,column_position
from dba_ind_columns
where table_owner in (select username from sys.t_user_cfg)
;
--check tab columns no rows selected
select owner,table_name,column_name,data_type,data_length,nullable,column_id from dba_tab_columns@dblink_migup
where owner in (select username from sys.t_user_cfg)
and table_name not like ‘BIN$%‘
minus
select owner,table_name,column_name,data_type,data_length,nullable,column_id from dba_tab_columns
where owner in (select username from sys.t_user_cfg)
;
--check comments no rows selected
select owner,table_name,column_name,comments from dba_col_comments@dblink_migup
where owner in (select username from sys.t_user_cfg)
and table_name not like ‘BIN$%‘
minus
select owner,table_name,column_name,comments from dba_col_comments
where owner in (select username from sys.t_user_cfg)
;
------check profile
select * from dba_profiles@dblink_migup
minus
select * from dba_profiles ;
------check mview
select owner,mview_name,container_name,query_len,rewrite_enabled,refresh_mode,refresh_method from dba_mviews@dblink_migup
where owner in (select username from sys.t_user_cfg)
minus
select owner,mview_name,container_name,query_len,rewrite_enabled,refresh_mode,refresh_method from dba_mviews
where owner in (select username from sys.t_user_cfg)
;
select owner,mview_name,container_name,query_len,rewrite_enabled,refresh_mode,refresh_method from dba_mviews@dblink_migup
minus
select owner,mview_name,container_name,query_len,rewrite_enabled,refresh_mode,refresh_method from dba_mviews ;
-----check user
select a.username,a.password apwd,b.password bpwd,a.profile apf,b.profile bpf,
a.account_status acs,b.account_status bcs
From
(
select du.username,su.password,du.profile,du.account_status
from dba_users@dblink_migup du,sys.user$ su
where username in (select username from sys.t_user_cfg) and du.username = su.name
) a
,
(
select du.username,su.password,du.profile,du.account_status
from dba_users du,sys.user$ su
where du.username in (select username from sys.t_user_cfg)
and du.username = su.name
) b
Where a.username = b.username And (a.password <> b.password Or a.profile <> b.profile Or a.account_status <> b.account_status);
--------check trigger--
select owner,trigger_name,trigger_type,table_owner,table_name,column_name,status
from dba_triggers@dblink_migup
where owner in (select username from sys.t_user_cfg)
minus
select owner,trigger_name,trigger_type,table_owner,table_name,column_name,status from dba_triggers
where owner in (select username from sys.t_user_cfg)
;
--check table owner trigger no rows selected
select owner,trigger_name,trigger_type,table_owner,table_name,column_name,status
from dba_triggers@dblink_migup
where table_owner in (select username from sys.t_user_cfg)
minus
select owner,trigger_name,trigger_type,table_owner,table_name,column_name,status from dba_triggers
where table_owner in (select username from sys.t_user_cfg)
;
select owner,trigger_name,trigger_type,table_owner,table_name,column_name
from dba_triggers@dblink_migup
minus
select owner,trigger_name,trigger_type,table_owner,table_name,column_name
from dba_triggers;
----------check sequence---------------------
select ds.sequence_owner,
ds.sequence_name,
ds.min_value,
ds.max_value,
ds.increment_by,
ds.cycle_flag,
ds.order_flag,
ds.cache_size,
ds.last_number
from dba_sequences@dblink_migup ds
where sequence_owner in (select username from sys.t_user_cfg)
minus
select ds.sequence_owner,
ds.sequence_name,
ds.min_value,
ds.max_value,
ds.increment_by,
ds.cycle_flag,
ds.order_flag,
ds.cache_size,
ds.last_number
from dba_sequences ds
where sequence_owner in (select username from sys.t_user_cfg)
;
###################################
3.OGG 安裝
上傳不同平臺的goldengate軟件 gg軟件兩個平臺都要安裝
"goldengate臨時裝到data卷上
1.cd /db/{ORACLE_SID}/data
mkdir goldendate
2.unzip goldengate軟件
" 請註意 goldengate 軟件區分os平臺和oracle版本 ,另外對於RAC,goldengate軟件安裝目錄需要設置為共享存儲
"cd
vi .profile
##追加以下內容
GGS_HOME=/db/{ORACLE_SID}/data/goldengate
export GGS_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$GGS_HOME:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
PATH=$GGS_HOME:$PATH
export PATH
hp-unix:step:
. ./profile_bcds
" "1、請註意平臺不同,profile文件配置也不同
2、對於RAC,每個節點上的profile都需要配置;"
"1.檢查:
select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
2.如果是未有, 打開supplementary log:
set timing on
alter system checkpoint;
alter system checkpoint;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;" "1.linux 結果如下:
SUPPLEME
--------
YES
2.hp unix 結果如下:
SQL> select SUPPLEMENTAL_LOG_DATA_MIN from v$database;
SUPPLEME
--------
YES
"
"create user ggmgr identified by ggmgr123 default tablespace users temporary tablespace temp;
grant create session,alter session to ggmgr;
grant alter system to ggmgr;
grant resource to ggmgr;
grant connect to ggmgr;
grant select any dictionary to ggmgr;
grant flashback any table to ggmgr;
grant select any table to ggmgr;
grant select any table to ggmgr;
grant insert any table to ggmgr;
grant update any table to ggmgr;
grant delete any table to ggmgr;
grant select on dba_clusters to ggmgr;
grant execute on dbms_flashback to ggmgr;
grant create table to ggmgr;
grant create sequence to ggmgr;
grant alter any table to ggmgr;
grant dba to ggmgr;
grant lock any table to ggmgr;" 1.linux/hp-unix done
"cd $GGS_HOME
mkdir direnv"
./ggsci
"create subdirs
exit"
"cd $GGS_HOME
./ggsci
GGSCI> EDIT PARAMS ./GLOBALS
--輸入如下內容
CHECKPOINTTABLE ggmgr.gg_checkpoint_tab
syslog none" "1.linux/hp-unix done
當使用GG版本11.x時,需要在GG manager參數中配置syslog none,使gg日誌不寫入操作系統的syslog。"
"GGSCI> DBLOGIN USERID ggmgr, PASSWORD ggmgr123
GGSCI> ADD CHECKPOINTTABLE ggmgr.gg_checkpoint_tab
GGSCI>exit" 1.linux/hp-unix done
"cd $GGS_HOME/direnv
1.vi db.oby
SETENV (ORACLE_SID = ""bcds"")
2.vi user.oby
userid ggmgr, password ggmgr123
" "1.linux/hp-unix done
ORACLE_SID = ""bcds"" 註意大小寫要和環境變量保持一致"
"cd $GGS_HOME/dirprm
vi mgr.prm
port 7809
dynamicportlist 7809-7819
autostart er *
autorestart er *, retries 24, waitminutes 3, resetminutes 1440
lagreportminutes 10
laginfoseconds 30
LAGCRITICALMINUTES 45
purgeoldextracts ./dirdat/*, usecheckpoints, minkeephours 168
" "
1.linux/hp-unix done
刪除PURGEDDLHISTORY MINKEEPDAYS 7, MAXKEEPDAYS 10 "
"cd $GGS_HOME
./ggsci
start mgr"
info mgr
GGSCI>dblogin userid ggmgr, password ggmgr12
2.遷移當天設置回滾環境
準備參數文件 準備e進程、d進程、r進程的參數文件
為ggmgr用戶臨時授權 "grant insert any table to ggmgr;
grant delete any table to ggmgr;
grant update any table to ggmgr;
"
設置參數 alter system set ENABLE_GOLDENGATE_REPLICATION=true scope=both;
創建gg_send表 "CREATE TABLE ggmgr.GG_SEND(
TESTER VARCHAR2(30) NOT NULL,
SOURCE_DATABASE VARCHAR2(10) NOT NULL,
TARGET_DATABASE VARCHAR2(10) NOT NULL,
TEST_TIME DATE DEFAULT SYSDATE,
Constraint PK_GG_SEND primary KEY (TESTER, SOURCE_DATABASE, TARGET_DATABASE, TEST_TIME) );
COMMENT ON COLUMN ggmgr.GG_SEND.TESTER IS ‘測試人員UM賬號‘;
COMMENT ON COLUMN ggmgr.GG_SEND.SOURCE_DATABASE IS ‘源數據庫SID‘;
COMMENT ON COLUMN ggmgr.GG_SEND.TARGET_DATABASE IS ‘目標數據庫SID‘;
COMMENT ON COLUMN ggmgr.GG_SEND.TEST_TIME IS ‘測試時間‘;
COMMENT ON TABLE ggmgr.GG_SEND is ‘GoldenGate接收端連通性測試表‘;
"
添加trandata "cd $GGS_HOME
./ggsci
dblogin userid ggmgr password ggmgr123
delete trandata BBSP.*
delete trandata BBSPODS.*
delete trandata BCDPETL.*
add trandata BBSP.*
add trandata BBSPODS.*
add trandata BCDPETL.*
"
對超過32列無主鍵的表添加trandata "
執行/tmp/dba/add_trandata_long32.sql
--報錯WARNING OGG-01387需要執行"
檢查trandata是否添加成功 "執行下面sql,返回空為成功。
select ‘add trandata ‘||owner||‘.‘|| table_name from dba_tables where owner in (‘BBSP‘,‘ BBSPODS‘,‘BCDPETL‘) and table_name not in (select distinct table_name from dba_log_group_columns where owner in (‘BBSP‘,‘ BBSPODS‘,‘BCDPETL‘));
--排除掉一些臨時備份表
"
上傳參數文件 "cd $GGS_HOME/dirprm
將e_rollbk.prm,d_rollbk.prm上傳到此目錄下
chown -R opbcds:dba /ogg/bcds/dirprm
"
創建GG進程 "cd $GGS_HOME
./ggsci
dblogin userid ggmgr password ggmgr123
add extract e_rollbk, tranlog, begin now
add exttrail ./dirdat/e1, extract e_rollbk, megabytes 50
add extract d_rollbk, exttrailsource ./dirdat/e1, params dirprm/d_rollbk.prm
add rmttrail ./dirdat/dr, extract d_rollbk, megabytes 50
"
修改回滾鏈路r進程參數文件 "cd $GGS_HOME/dirprm
上傳r_rollbk.prm
chown -R opbcds:dba /oggfs/ogg/dirprm "
創建GG進程 "cd $GGS_HOME
./ggsci
dblogin userid ggmgr password ggmgr123
add replicat r_rollbk, exttrail ./dirdat/dr, params dirprm/r_rollbk.prm , CHECKPOINTTABLE ggmgr.gg_checkpoint_tab
"
創建目標端連通性測試表 " CREATE TABLE ggmgr.GG_RECEIVE_R_ROLLBK(
TESTER VARCHAR2(30) NOT NULL,
SOURCE_DATABASE VARCHAR2(10) NOT NULL,
TARGET_DATABASE VARCHAR2(10) NOT NULL,
TEST_TIME DATE DEFAULT SYSDATE,
Constraint PK_GG_RECEIVE_R_ROLLBK primary KEY (TESTER, SOURCE_DATABASE, TARGET_DATABASE, TEST_TIME) );
COMMENT ON COLUMN ggmgr.GG_RECEIVE_R_ROLLBK.TESTER IS ‘測試人員UM賬號‘;
COMMENT ON COLUMN ggmgr.GG_RECEIVE_R_ROLLBK.SOURCE_DATABASE IS ‘源數據庫SID‘;
COMMENT ON COLUMN ggmgr.GG_RECEIVE_R_ROLLBK.TARGET_DATABASE IS ‘目標數據庫SID‘;
COMMENT ON COLUMN ggmgr.GG_RECEIVE_R_ROLLBK.TEST_TIME IS ‘測試時間‘;
COMMENT ON TABLE ggmgr.GG_RECEIVE_R_ROLLBK is ‘GoldenGate接收端連通性測試表‘;
"
禁用級聯刪除和觸發器 "SELECT ‘alter table ‘||owner||‘.‘||table_name||‘ disable constraint ‘||constraint_name||‘;‘
FROM dba_constraints
WHERE owner in (‘BBSP‘,‘ BBSPODS‘,‘BCDPETL‘)
AND constraint_type = ‘R‘
ORDER BY constraint_type desc, owner, table_name, constraint_name;
select ‘alter trigger ‘||owner||‘.‘||trigger_name||‘ disable ;‘
from all_triggers
where owner in (‘BBSP‘,‘ BBSPODS‘,‘BCDPETL‘)
order by owner,trigger_name;
復核:
select owner,table_name,constraint_name,status from dba_constraints where owner in (‘BBSP‘,‘ BBSPODS‘,‘BCDPETL‘) and constraint_type = ‘R‘ and status <> ‘DISABLED‘; --無結果產出
select owner,trigger_name,table_owner,table_name,status from dba_triggers where owner in (‘BBSP‘,‘ BBSPODS‘,‘BCDPETL‘) and status <> ‘DISABLED‘; --無結果產出
"
啟動extract和dump進程 "start e_rollbk
start d_rollbk
info all
<進程都是RUNNING狀態>"
啟動同步到unix的回滾R進程 "cd $GGS_HOME
./ggsci
start r_rollbk
"
插入測試信息 "sqlplus ‘/as sysdba‘
insert into ggmgr.GG_SEND values(‘測試‘,‘source_sid‘,‘target_sid‘,SYSDATE);
commit;"
檢測測試信息是否同步過來 "sqlplus ‘/as sysdba‘
select * from ggmgr.GG_RECEIVE_R_ROLLBK ;
"
3.3 OGG PKG
查看32列以上沒有主鍵的表 :
1.部署pkg
2.執行查詢
SET termout OFF feedback OFF verify OFF echo OFF heading OFF trims ON escape ON pages 0 linesize 999 long 3000
select trim(sql_add_supp) from TABLE(
select cast(gg_supplemental_32.sql_supplemental_32(‘BBSP‘)
as gg_supplemental_32_table_type )
from dual
);
Pkg info:
create or replace type gg_supplemental_32_row_type as object
(
owner varchar2(32),
table_name varchar2(32),
seq# number,
sql_add_supp varchar2(2048)
);
/
create or replace type gg_supplemental_32_table_type as table of gg_supplemental_32_row_type;
/
create or replace package gg_supplemental_32 AUTHID CURRENT_USER is
function sql_supplemental_32(i_owner varchar2)
return gg_supplemental_32_table_type;
end gg_supplemental_32;
/
create or replace package body gg_supplemental_32 as
function sql_supplemental_32(i_owner varchar2)
return gg_supplemental_32_table_type as
z_data gg_supplemental_32_table_type := gg_supplemental_32_table_type();
n number;
cursor c is
select dt.owner || ‘.‘ || dt.table_name obj,
dt.column_name,
dt.table_name,
dt.owner,
Row_Number() over(partition by dt.owner || ‘.‘ || dt.table_name order by dt.column_name) rn,
do.object_id
from dba_tab_columns dt, dba_objects do
where dt.owner = i_owner
and dt.data_type not in
(‘CLOB‘, ‘BLOB‘, ‘NCLOB‘, ‘LONG‘, ‘LONG RAW‘, ‘ANYDATA‘,
‘ALERT_TYPE‘, ‘XMLTYPE‘, ‘WM_PERIOD‘, ‘SQL_PLAN_TABLE_TYPE‘,
‘BFILE‘)
and dt.data_type not like ‘%$%‘
and dt.owner = do.owner
and dt.table_name = do.object_name
and dt.table_name in
(SELECT distinct (table_name) obj
FROM dba_tab_columns
WHERE owner = i_owner
AND column_id > 32
AND table_name in
(SELECT table_name
FROM dba_tables
WHERE owner = i_owner
MINUS (SELECT obj1.name
FROM SYS.user$ user1,
SYS.user$ user2,
SYS.cdef$ cdef,
SYS.con$ con1,
SYS.con$ con2,
SYS.obj$ obj1,
SYS.obj$ obj2
WHERE user1.name = i_owner
AND cdef.type# = 2
AND con2.owner# = user2.user#(+)
AND cdef.robj# = obj2.obj#(+)
AND cdef.rcon# = con2.con#(+)
AND obj1.owner# = user1.user#
AND cdef.con# = con1.con#
AND cdef.obj# = obj1.obj#
UNION
SELECT idx.table_name
FROM dba_indexes idx
WHERE idx.owner = i_owner
AND idx.uniqueness = ‘UNIQUE‘)));
obj_prev varchar2(200);
obj_flag number;
sql_add_supp varchar2(4000);
sql_post varchar2(2000);
n_g number;
pre_n_g number;
z_owner varchar2(32);
z_table_name varchar2(32);
begin
sql_post := ‘) always;‘;
obj_flag := 0;
for x in c loop
n_g := trunc((x.rn - 1) / 32) + 1;
n := mod(x.rn, 32);
z_owner := x.owner;
z_table_name := x.table_name;
if obj_prev is null then
sql_add_supp := ‘ALTER TABLE ‘ || x.obj ||
‘ ADD SUPPLEMENTAL LOG GROUP GGS_‘ ||
substr(x.table_name, 1, 16) || ‘_‘ || x.object_id || ‘_‘ || n_g || ‘(‘ ||
x.column_name;
obj_prev := x.obj;
pre_n_g := n_g;
elsif (obj_prev = x.obj) then
if (n_g <> pre_n_g) then
-- print out sql statement
sql_add_supp := sql_add_supp || sql_post;
z_data.extend;
z_data(z_data.count) := gg_supplemental_32_row_type(z_owner,
z_table_name,
n_g,
sql_add_supp);
-- reset
pre_n_g := n_g;
sql_add_supp := ‘ALTER TABLE ‘ || x.obj ||
‘ ADD SUPPLEMENTAL LOG GROUP GGS_‘ ||
substr(x.table_name, 1, 16) || ‘_‘ || x.object_id || ‘_‘ || n_g || ‘(‘ ||
x.column_name;
else
sql_add_supp := sql_add_supp || ‘ ,‘ || x.column_name;
end if;
else
-- print out sql statement
sql_add_supp := sql_add_supp || sql_post;
z_data.extend;
z_data(z_data.count) := gg_supplemental_32_row_type(z_owner,
z_table_name,
n_g,
sql_add_supp);
-- reset
pre_n_g := n_g;
obj_prev := x.obj;
sql_add_supp := ‘ALTER TABLE ‘ || x.obj ||
‘ ADD SUPPLEMENTAL LOG GROUP GGS_‘ ||
substr(x.table_name, 1, 16) || ‘_‘ || x.object_id || ‘_‘ || n_g || ‘(‘ ||
x.column_name;
end if;
end loop;
-- print last sql if exist --
sql_add_supp := sql_add_supp || sql_post;
z_data.extend;
z_data(z_data.count) := gg_supplemental_32_row_type(z_owner,
z_table_name,
n_g,
sql_add_supp);
return z_data;
end sql_supplemental_32;
end;
/
數據庫遷移expdp impdp 與 OGg 搭建