您好,登錄后才能下訂單哦!
實驗環境:
源庫: 192.168.2.200 SID=testdb
目標庫:192.168.2.100 SID=testdb
實驗目的:
使用impdp+dblink的方式 將192.168.2.200數據庫上的jtrms用戶的所有數據導入到目標數據庫192.168.2.100
注意:使用impdp+dblink 的方式,這樣就節省了數據導出(expdp),然后再導入的過程。
實施步驟:
一、源庫操作:
1、首先檢查源庫要遷移的用戶信息:
SQL> select USERNAME,DEFAULT_TABLESPACE from dba_users where USERNAME like 'JTRMS'; ---檢查用戶的默認表空間
USERNAME DEFAULT_TABLESPACE
------------------------------ ------------------------------
JTRMS TEST
2、該用戶的表空間大小
SQL> select TABLESPACE_NAME,BYTES from dba_data_files where TABLESPACE_NAME like 'TEST';
TABLESPACE_NAME BYTES
------------------------------ ----------
TEST 314572800
SQL> show user;
USER is "JTRMS"
SQL> select * from tab; ----檢查該用戶一共有97張表
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
ECR_ANNOUNCEMENT TABLE
ECR_APPROVAL TABLE
ECR_APPROVAL_TO_RECEIVE TABLE
ECR_BP_SYN TABLE
ECR_CHANGE TABLE
JFORUM_THEMES TABLE
JFORUM_TOPICS TABLE
JFORUM_TOPICS_WATCH TABLE
JFORUM_USERS TABLE
JFORUM_USER_GROUPS TABLE
JFORUM_VOTE_DESC TABLE
JFORUM_VOTE_RESULTS TABLE
JFORUM_VOTE_VOTERS TABLE
JFORUM_WORDS TABLE
SYS_TEMP_FBT TABLE
。。。。。。。
。。。。。。。
97 rows selected.
3、查看該用戶下的索引信息:
SQL> set linesize 300 pagesize 300
SQL> select INDEX_NAME,TABLE_OWNER,STATUS,NUM_ROWS from user_indexes;
4、查看該用戶下所有的job信息
alter session set nls_date_format = 'yyyy-mm-dd hh34:mi:ss';
set linesize 300 pagesize 300
col what for a50
col interval for a50
select job,what,LAST_DATE,NEXT_DATE,SCHEMA_USER,interval from user_jobs;
二、在目標數據庫上操作
注意:在目標數據庫創建用戶信息之前,一定要檢查目標看是否有該用戶的信息,和表空間是否有重名等
1、在目標數據庫上創建用戶信息---一切以源庫為標準
SQL> create tablespace test datafile '/opt/oracle/test.dbf' size 300M; ---創建test表空間
SQL> create user jtrms identified by jtrms default tablespace test; ---創建jtrms用戶
SQL> grant connect,resource to jtrms; ---對該用戶授權
SQL> grant dba to jtrms;
2、在目標數據庫增加源庫的tns文件信息,并測試連接源庫
[oracle@test ~]$ vim tnsnames.ora
testdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.200)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdb)
)
)
---注意,增加的是源庫192.168.2.200的信息
[oracle@test ~]$ sqlplus jtrms/jtrms@testdb ; ----使用jtrms用戶連接源庫192.168.2.200
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jun 5 00:54:31 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
testdb
3、在目標數據庫上創建dblink
create public database link testlink connect to jtrms identified by jtrms
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.200)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = testdb)
)
)';
注意:該dblink是連接源庫用的
4、在目標數據庫上,開始使用下面的命令將源庫jtrms用戶的數據使用dblink導入到目標庫
[oracle@test ~]$ impdp jtrms network_link=testlink schemas=jtrms cluster=N PARALLEL=2
Import: Release 11.2.0.4.0 - Production on Mon Jun 5 01:03:16 2017
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Password: ---輸入用戶的密碼
5、登錄數據庫,驗證數據是否傳輸成功:
[oracle@test ~]$ sqlplus '/as sysdba'
SQL*Plus: Release 11.2.0.4.0 Production on Mon Jun 5 01:06:34 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn jtrms/jtrms
SQL> select count(*) from tab;
COUNT(*)
----------
97
SQL> set linesize 300 pagesize 300
SQL> select INDEX_NAME,TABLE_OWNER,STATUS,NUM_ROWS from user_indexes;
INDEX_NAME TABLE_OWNER STATUS NUM_ROWS
------------------------------ ------------------------------ -------- ----------
IDX_BOK_REL JTRMS VALID 0
IDX_BOK_USER JTRMS VALID 0
SYS_C0011373 JTRMS VALID 0
SYS_C0011372 JTRMS VALID 0
IDX_BANLIST_EMAIL JTRMS VALID 0
-----至此,實施完成;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。