資料庫升級之-資料泵

yingyifeng306發表於2020-08-11

資料庫邏輯遷移 描述

1) 源端資料庫全庫匯出,並生成 *.dmp 檔案; 2) 將源端 *.dmp 檔案複製至目標端; 3) *.dmp 資料全庫匯入目標資料庫。在資料遷移至目標資料庫後,目標庫的某些物件可能處於失效狀態, 指令碼對無效物件進行重編譯處理,編譯之後可進行業務測試,驗證資料的可用性和完整性。

源庫匯出

檢視源庫字符集

SQL>   col value for a60

SQL>   set line 200

SQL>   select * from nls_database_parameters where parameter='NLS_CHARACTERSET';

PARAMETER                      VALUE

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

NLS_CHARACTERSET                ZHS16GBK


統計源庫表空間資料量

檢視源庫當前表空間實際資料量

SQL>   set line 200

SQL>   set pagesize 0

SQL>   select tablespace_name,sum(bytes)/1024/1024/1024 G from dba_segments group by   tablespace_name order by sum(bytes)/1024/1024/1024 desc;

KYERP                106.169922

NNC_DATA03            62.800354

INDX                   61.12677

NNC_INDEX03          57.1514282

NNC_DATA01           36.8331299

IUFO                 11.3796997

SYSTEM               2.91809082

NNC_INDEX01          2.49285889

NNC_DATA02           2.44415283

NNC_INDEX02           1.9274292

USERS                1.77923584

SYSAUX               1.33441162

UNDOTBS1             .477783203

PERFSTAT             .154052734

KYBB                 .005371094

TEST                 .000061035

 

檢視源庫目錄物件

使用 DataPump 全庫匯出需要指定目錄物件引數,以下返回結果為預設的目錄物件。建議不要採用預設的目錄物件,可手動建立目錄物件(即自定義)

SQL>   col directory_path for a60

SQL>   set line 200

SQL>   select * from dba_directories;

OWNER      DIRECTORY_NAME       DIRECTORY_PATH

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

SYS        XMLDIR                 /oracle/app/product/11.2.0/db_1/rdbms/xml

SYS        DATA_PUMP_DIR       /oracle/app/admin/orcl/dpdump/

 

手動建立目錄物件 dumpdir ,確保作業系統層面存在 /backup 目錄結構及預留足夠的磁碟空間

create   directory dumpdir as '/backup';

grant all   on directory dumpdir to public;

 

源庫全庫匯出

源庫匯出並開啟 4 個並行

$cd   /backup

$curr_date=`date   +%Y%m%d%H%M%S`

$export   NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

$ nohup   expdp "'"/ as sysdba"'" directory=dumpdir   dumpfile=fulldb_${curr_date}_%U.dmp logfile=fulldb_${curr_date}.log full=y   PARALLEL=4 EXCLUDE=STATISTICS &

複製*.dmp 檔案至目標端/backup

源庫*.dmp 檔案確認

$ ls -rtl

-rw-r-----   1 oracle   dba        10496659456   Jul 23 00:06 fulldb_20170722185135_04.dmp

-rw-r-----   1 oracle   dba        50410315776   Jul 23 00:06 fulldb_20170722185135_03.dmp

-rw-r-----   1 oracle   dba        51765604352   Jul 23 00:06 fulldb_20170722185135_02.dmp

-rw-r-----   1 oracle   dba        66040819712   Jul 23 00:06 fulldb_20170722185135_01.dmp

-rw-r--r--   1 oracle   dba           2870936 Jul 23 00:06 fulldb_20170722185135.log

 

確認成功匯出

Master table "SYS"."SYS_EXPORT_FULL_01"   successfully loaded/unloaded

******************************************************************************

Dump file set for SYS.SYS_EXPORT_FULL_01 is:

    /backup/fulldb_20170722185135_01.dmp

  /backup/fulldb_20170722185135_02.dmp

    /backup/fulldb_20170722185135_03.dmp

    /backup/fulldb_20170722185135_04.dmp

Job "SYS"."SYS_EXPORT_FULL_01" successfully completed at 00:06:26

 

將源端*.dmp 檔案傳至目標端

ftp 傳輸 dmp 檔案

$cd   /backup

$ ftp   10.10.1.5

ftp>   bin

ftp>   prompt

ftp>   lcd /backup

ftp> cd   /backup

ftp>   mput *.dmp

 

目標端確認*.dmp

確認目標端 dmp 檔案與源端 dmp 大小一致

[oracle@ncdb02 backup]# ls -rlt

-rw-r--r-- 1 oracle oinstall       2870936 Jul 23 00:25 fulldb_20170722185135.log

-rw-r--r-- 1 oracle oinstall 66040819712 Jul 23 00:44 fulldb_20170722185135_01.dmp

-rw-r--r-- 1 oracle oinstall 51765604352 Jul 23 01:01   fulldb_20170722185135_02.dmp

-rw-r--r-- 1 oracle oinstall 50410315776 Jul 23 01:41   fulldb_20170722185135_03.dmp

-rw-r--r-- 1 oracle oinstall 10496659456 Jul 23 01:50 fulldb_20170722185135_04.dmp

 

目標庫匯入

檢視目標庫字符集

確認目標庫資料庫字符集

SQL>   col value for a60

SQL>   set line 200

SQL>   select * from nls_database_parameters where parameter='NLS_CHARACTERSET';

PARAMETER                      VALUE

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

NLS_CHARACTERSET                ZHS16GBK

 

目標庫建立源庫對應表空間

目標庫表空間與源庫表空間要保持一致

create tablespace KYERP datafile   '+DATA/ncerp/kyerp01.dbf' size 30g autoextend off;

alter tablespace KYERP add datafile   '+DATA/ncerp/kyerp02.dbf' size 30g autoextend off;

alter tablespace KYERP add datafile   '+DATA/ncerp/kyerp03.dbf' size 30g autoextend off;

alter tablespace KYERP add datafile   '+DATA/ncerp/kyerp04.dbf' size 30g autoextend off;

create tablespace NNC_DATA03 datafile   '+DATA/ncerp/nnc_data03_01.dbf' size 30g autoextend off;

alter tablespace NNC_DATA03 add datafile   '+DATA/ncerp/nnc_data03_02.dbf' size 30g autoextend off;

alter tablespace NNC_DATA03 add datafile   '+DATA/ncerp/nnc_data03_03.dbf' size 30g autoextend off;

create tablespace INDX datafile   '+DATA/ncerp/indx01.dbf' size 30g autoextend off;

alter tablespace INDX add datafile   '+DATA/ncerp/indx02.dbf' size 30g autoextend off;

alter tablespace INDX add datafile   '+DATA/ncerp/indx03.dbf' size 30g autoextend off;

create tablespace NNC_INDEX03 datafile   '+DATA/ncerp/nnc_index03_01.dbf' size 30g autoextend off;

alter tablespace NNC_INDEX03 add datafile   '+DATA/ncerp/nnc_index03_02.dbf' size 30g autoextend off;

alter tablespace NNC_INDEX03 add datafile   '+DATA/ncerp/nnc_index03_03.dbf' size 30g autoextend off;

create tablespace NNC_DATA01 datafile   '+DATA/ncerp/nnc_data01_01.dbf' size 30g autoextend off;

alter tablespace NNC_DATA01 add datafile   '+DATA/ncerp/nnc_data01_02.dbf' size 30g autoextend off;

create tablespace IUFO datafile '+DATA/ncerp/iufo01.dbf'   size 30g autoextend off;

create tablespace NNC_INDEX01 datafile   '+DATA/ncerp/nnc_index01_01.dbf' size 10g autoextend on next 1g maxsize 30g;

create tablespace NNC_DATA02 datafile   '+DATA/ncerp/nnc_data02_01.dbf' size 10g autoextend on next 1g maxsize 30g;

create tablespace NNC_INDEX02 datafile   '+DATA/ncerp/nnc_index02_01.dbf' size 10g autoextend on next 1g maxsize 30g;

create tablespace PERFSTAT datafile   '+DATA/ncerp/perfstat.dbf' size 1g autoextend on next 1g maxsize 30g;

create tablespace KYBB datafile   '+DATA/ncerp/kybb01.dbf' size 1g autoextend on next 1g maxsize 30g;

create tablespace TEST datafile   '+DATA/ncerp/test01.dbf' size 1g autoextend on next 1g maxsize 30g;

 

檢視目標庫表空間預分配空間

目標庫表空間的預分配空間確保大於源庫對應表空間的實際使用空間

SQL>   select tablespace_name,sum(bytes)/1024/1024/1024 G from dba_data_files where   tablespace_name in   ('KYERP','NNC_DATA03','NNC_INDEX03','INDX','NNC_DATA01','IUFO','NNC_DATA02','NNC_INDEX01','NNC_INDEX02','TEST','PERFSTAT','KYBB')   group by tablespace_name order by sum(bytes)/1024/1024/1024 desc;

KYERP                150

NNC_DATA03           120

NNC_INDEX03           90

INDX                  90

NNC_DATA01            60

IUFO                  30

NNC_INDEX01           10

NNC_DATA02            10

NNC_INDEX02           10

TEST                   1

KYBB                   1

PERFSTAT               1

 

檢視目標庫目錄物件

使用 DataPump 全庫匯入需要指定目錄物件引數,以下返回結果為預設的目錄物件。建議不要採用預設的目錄物件,可手動建立目錄物件(即自定義)

SQL>   col directory_path for a60

SQL>   set line 200

SQL>   select * from dba_directories;

OWNER      DIRECTORY_NAME       DIRECTORY_PATH

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

SYS        XMLDIR                 /oracle/app/product/11.2.0/db_1/rdbms/xml

SYS        DATA_PUMP_DIR       /oracle/app/admin/orcl/dpdump/

 

手動建立目錄物件 dumpdir ,確保在作業系統層面存在 /backup 目錄結構及足夠的磁碟空間

create   directory dumpdir as '/backup';

grant all   on directory dumpdir to public;

 

目標庫全庫匯入

$export   NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

$nohup impdp "'"/   as sysdba"'" directory=dumpdir   dumpfile=fulldb_20170722185135_%U.dmp logfile=fulldb_20170723_impdp.log   full=y PARALLEL=4 CLUSTER=n &

 

目標庫編譯無效物件

無效物件重新編譯

SQL> @?/rdbms/admin/utlrp.sql

 

目標庫統計物件收集

資料庫相關物件統計資訊收集

SQL> exec   dbms_stats.gather_fixed_objects_stats;

SQL> exec   dbms_stats.gather_dictionary_stats(estimate_percent=>10,Degree=>8,Cascade=>TRUE,Granularity=>'ALL');

SQL> exec   dbms_stats.gather_database_stats(estimate_percent=>10,Degree=>8,Cascade=>TRUE,Granularity=>'ALL');

 

目標庫連線測試

在新伺服器本地測試目標庫連線

sqlplus system/oracle@10.10.1.8:1521/ncerp

sqlplus system/oracle@10.10.1.7:1521/ncerp

sqlplus system/oracle@10.10.1.6:1521/ncerp

sqlplus system/oracle@10.10.1.5:1521/ncerp

sqlplus system/oracle@10.10.1.4:1521/ncerp


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23732248/viewspace-2710656/,如需轉載,請註明出處,否則將追究法律責任。

相關文章