1. 程式人生 > >oracle 11g 表空間遷移 實驗過程

oracle 11g 表空間遷移 實驗過程

 


參考文件:

在複製或移動表空間前,使用者首先將表空間置於只讀狀態,再複製表空間的資料檔案(datafile),
最後使用export/import工具遷移位於資料字典(data dictionary)中的資料庫元資料資訊(database metadata information)。
資料檔案以及元資料匯出檔案必須全部複製到目標資料庫上。
移動這些檔案時可以使用任何用於檔案複製的工具,例如作業系統的複製功能,FTP,或者釋出到CD中。
複製資料檔案(datafile)並匯入元資料(metadata)之後,使用者可以選擇是否將表空間(tablespace)置為可讀寫狀態。

環境介紹:

作業系統 :widows 2003 裝在虛擬機器上的
oracle 版本:11g

oracle 有兩個例項 第一個例項名稱 orcl 第二個 orcl2


sqlplus /nolog

--連線例項  orcl
connect /@orcl as sysdba

--在 orcl 建立表空間 test 包含一個數據檔案
create tablespace test datafile 'C:\oracle11g\app\Administrator\oradata\orcl\test01.dbf' size 10m;
--drop tablespace test; --如果想刪除表空間用此語句

--建立一個使用者 密碼為 123456 預設表空間為test
create user xuejianxin identified by 123456 default tablespace test;
--給此使用者授權為dba
grant dba to xuejianxin;


--用剛才建立的使用者  連線例項  orcl
connect xuejianxin/[email protected];
--建立表
create table test(id int,name varchar2(10));
--插入資料
insert into test values (1,'xue1');
insert into test values (1,'xue2');
--提交
commit;
--修改表空間為只讀
alter tablespace test read only; 
--恢復表空間為正常狀態
-- alter tablespace test read wirite ;
--execute sys.dbms_tts.transport_set_check('test',true); --此句可以不執行


--匯出test 表空間 元資料
/**
DIRECTORY
指定轉儲檔案和日誌檔案所在的目錄
DIRECTORY=directory_object
Directory_object用於指定目錄物件名稱.需要注意,
目錄物件是使用CREATE DIRECTORY語句建立的物件,而不是OS目錄
Expdp scott/tiger DIRECTORY=dump DUMPFILE=a.dump
*/

connect /@orcl as sysdba
create directory dump as 'c:\dump' --必須建立此目錄 c:\dump
drop directory dump;
exit;

--在 cmd 中直接 執行此命令
expdp system/[email protected] directory=dump  dumpfile=test.dmp  transport_tablespaces=test

C:\Documents and Settings\Administrator>expdp system/[email protected] directory=dump
 dumpfile=test.dmp  transport_tablespaces=test

Export: Release 11.1.0.6.0 - Production on 星期五, 01 7月, 2011 0:58:31

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

連線到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
啟動 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/********@orcl directory=dum
p dumpfile=test.dmp transport_tablespaces=test
處理物件型別 TRANSPORTABLE_EXPORT/PLUGTS_BLK
處理物件型別 TRANSPORTABLE_EXPORT/TABLE
處理物件型別 TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
已成功載入/解除安裝了主表 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01"
******************************************************************************
SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 的轉儲檔案集為:
  C:\DUMP\TEST.DMP
******************************************************************************
可傳輸表空間 TEST 所需的資料檔案:
  C:\ORACLE11G\APP\ADMINISTRATOR\ORADATA\ORCL\TEST01.DBF
作業 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" 已於 01:00:02 成功完成


拷貝資料檔案 C:\oracle11g\app\Administrator\oradata\orcl\test01.dbf  到 C:\test01.dbf

--恢復表空間讀寫狀態
connect /@orcl as sysdba
alter tablespace test read write;

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

--連線例項 orcl2
connect /@orcl2 as sysdba;
--建立匯入需要的目錄
create directory dump as 'c:\dump'
exit;


--在cmd 中執行以下命令
impdp  system/[email protected] directory=dump dumpfile=test.dmp transport_datafiles=c:\test01.dbf remap_schema=xuejianxin:system

 
C:\Documents and Settings\Administrator>impdp  system/[email protected] directory=dum
p dumpfile=test.dmp transport_datafiles=c:\test01.dbf remap_schema=xuejianxin:sy
stem

Import: Release 11.1.0.6.0 - Production on 星期五, 01 7月, 2011 1:07:55

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

連線到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功載入/解除安裝了主表 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01"
啟動 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/********@orcl2 directory=du
mp dumpfile=test.dmp transport_datafiles=c:\test01.dbf remap_schema=xuejianxin:s
ystem
處理物件型別 TRANSPORTABLE_EXPORT/PLUGTS_BLK
ORA-39123: 資料泵可傳輸的表空間作業中止
ORA-29345: 無法使用不相容的字符集將表空間插入到資料庫中

作業 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" 因致命錯誤於 01:08:22 停止

結果發現orcl 例項 和orcl2 例項字符集不一樣

orcl 字符集為
select * from nls_database_parameters where parameter='NLS_CHARACTERSET'
--AL32UTF8

orcl2 字符集為 
select * from nls_database_parameters where parameter='NLS_CHARACTERSET'

--ZHS16GBK

connect /@orcl2 as sysdba;

SQL> alter system enable restricted session; --shutdown immediate   startup restrict


系統已更改。

SQL> alter database character set internal_use AL32UTF8;


shutdown immediate

SQL> connect /@orcl2 as sysdba
ERROR:
ORA-12514: TNS: 監聽程式當前無法識別連線描述符中請求的服務


SQL> conn /as sysdba
已連線到空閒例程。
SQL> startup
ORACLE 例程已經啟動。

Total System Global Area  263639040 bytes
Fixed Size                  1332552 bytes
Variable Size             222300856 bytes
Database Buffers           37748736 bytes
Redo Buffers                2256896 bytes
資料庫裝載完畢。

exit;


最後在cmd 執行 impdp  system/[email protected] directory=dum
p dumpfile=test.dmp transport_datafiles=c:\test01.dbf remap_schema=xuejianxin:sy
stem

由於 orcl2上沒有使用者xuejianxin 因此 remap_schema=xuejianxin:system
遷入了system方案 

C:\Documents and Settings\Administrator>impdp  system/[email protected] directory=dum
p dumpfile=test.dmp transport_datafiles=c:\test01.dbf remap_schema=xuejianxin:sy
stem

Import: Release 11.1.0.6.0 - Production on 星期五, 01 7月, 2011 1:38:13

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

連線到: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功載入/解除安裝了主表 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01"
啟動 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/********@orcl2 directory=du
mp dumpfile=test.dmp transport_datafiles=c:\test01.dbf remap_schema=xuejianxin:s
ystem
處理物件型別 TRANSPORTABLE_EXPORT/PLUGTS_BLK
處理物件型別 TRANSPORTABLE_EXPORT/TABLE
處理物件型別 TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
作業 "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" 已於 01:38:38 成功完成


connect /@orcl2 as sysdba

SQL> select * from system.test
  2  ;

        ID NAME
---------- --------------------
         1 xue1
         1 xue2


SQL>
SQL> connect /@orcl as sysdba
已連線。
SQL> drop directory dump;

目錄已刪除。

SQL> connect /@orcl2 as sysdba
已連線。
SQL> drop directory dump;

目錄已刪除。

相關推薦

oracle 11g 空間遷移 實驗過程

 參考文件:在複製或移動表空間前,使用者首先將表空間置於只讀狀態,再複製表空間的資料檔案(datafile),最後使用export/import工具遷移位於資料字典(data dictionary)中的資料庫元資料資訊(database metadata informatio

oracle 創建空間oracle 11g空間之最大最小

rop create default 數據文件 32位系統 conn dbf ide 剩余空間 /*分為四步 *//*第1步:創建臨時表空間 */create temporary tablespace emaoyi_temp tempfile ‘D:\app\Adminis

oracle 11g空間設定

oracle 11g表空間設定 1.檢視使用者對應的表空間 select username,default_tablespace from dba_users; 2.查看錶空間資料檔案 select * from dba_data_files where tablespac

oracle 11g空間之最大最小

oracle支援的檔案大小和他的db_block_size和db_block的數量決定的。在oracle 9i以前,oracle 的db_block的數量最大隻能為2的22次方個,而我們通過oracle預設的模板建的資

ORACLE空間、段、區和塊簡述 (11g

文章轉載自:http://blog.itpub.net/17203031/viewspace-682003/ 在Oracle學習過程中,儲存結構,表段區塊可能是每個初學者都要涉及到的概念。表空間、段、分割槽和資料塊分別表示了Oracle進行資料儲存的不同層次和結構。瞭解清楚這幾個結構,有助於我們奠定一個穩

exp-imp實現oracle不同空間遷移

 --1 在遷徙目標機上新建 create tablespace tzsb datafile 'I:\app\Administrator\oradata\orcl\tzsb01.dbf' size 500m create user wgm_tzsb identified

ORACLE空間建立和資料檔案的新增(11g

建立多資料檔案的表空間Create TABLESPACE TS_TAB  DATAFILE '/oracle/app/oradata/orcl/ecq_01.dbf'  SIZE 2147483648   AUTOEXTEND ON NEXT 52428800 MAXSIZE

Oracle UNDO空間對應的檔案在執行過程中丟失如何恢復

上次在blog中模擬了undo表空間對應的檔案在shutdown immediate後,在重新啟動之前丟失了,這僅僅是模擬而已,現實中這個時間段(shutdown immediate --- startup)這個期間丟失undo檔案的可能性幾乎沒有.這個情況的恢復請參照ht

Oracle不同空間之間的資料遷移

--將資料庫為testdb,使用者名稱為testuser中預設(users)表空間裡的資料遷移至表空間(newtablespace) --1.用system使用者登陸testdb資料庫,建立directory(testdir)並將讀、寫許可權授予testuser使用者

Oracle 審計AUD$遷移空間及創建清理job

xtend scheduler ble 新的 tab eve count pac true Oracle 10.2.0.5以上的版本可以使用DBMS_AUDIT_MGMT清理audit1、查看audit是否已經打開SQL> show parameter audit_t

ORACLE臨時空間總結

datafile 資源 indicate height 完成 round clip blocks rip 臨時表空間概念 臨時表空間用來管理數據庫排序操作以及用於存儲臨時表、中間排序結果等臨時對象,當ORACLE裏需要用到SORT的時候,並且當PGA中sort_ar

Oracle undo 空間不可用

line allow 如果 zed views 不存在 not 是否 pac      由於某次不小心操作,在切換表空間時沒有成功,但是由於把parameter undo的undo_management值改為了MANUAL所以在啟動數據庫時沒有報任何錯誤,但是給表插入數據時

Oracle刪除空間報ORA01548

nts 參數 回滾 sys 添加 files error ace fixed 由於undo表空間設置了自動增長,導致替換了好幾個undo表空間,就想把原先的undo表空間刪掉騰出空間 但刪的時候報錯 SQL> drop tablespace undotbs1 incl

oracle 臨時空間 占用磁盤空間

oracle 臨時表空間新創建一個臨時表空間 tmpacreate temporary tablespace TEMPA TEMPFILE ‘/oracle/tmp/tempa01.dbf ‘ SIZE 8192M REUSE AUTOEXTEND ON NEXT

Oracle空間、用戶、用戶權限的操作

option 應該 rain 建立 bsp 賬戶 停止 including ora 一、對表空間的操作 1、創建表空間(create tablespace) -- ‘hpdb_tablespace‘ 指定表空間名稱 -- ‘e:\hpdb.dbf‘ 指定表空間數據文件名稱

Oracle空間無權限

無權限 span 內存 空間 spa space alter table 用戶名 執行語句:     alter user username quota 1024m on tablespacename; 第一個是用戶名,第二個是指定該用戶可以使用多大的內存,第三個是

Oracle建立空間和用戶

creat 增長 pac files tor initial ide efault start Oracle建立表空間和用戶 建立表空間和用戶的步驟: 用戶 建立:create user 用戶名 identified by

Oracle收縮空間

tex build index from alt Owner segment where alter column SQLTEXT format a80 select count(*) from dba_segments where tablespace_name = ‘U

[Oracle]System 空間的文件丟失

oracl 空間 taf use data store targe iat serve 如果system 表空間的文件丟失,假設有備份的情況,可以恢復。數據庫需要設置為mount 狀態,然後restore/recover datafile模擬實驗:SQL> selec

[Oracle]undo空間使用量為100%

2種 奇怪 nvl ack ont expire sed code cccccc 在Toad中發現undo表空間undotbs1使用量已經達到100%,但是奇怪的是數據庫並沒有hang住,依然可以正常運轉 通過Oracle提供的EM查看undotbs1表空間的使用,也達到