Oracle管理磁碟空間和資源

來源:互聯網
上載者:User

Oracle管理磁碟空間和資源
1.可恢複的空間分配1.1 瞭解可恢複的空間分配

一般情況,我們發出一個大型資料庫操作,比如建立大表索引,如果資料表空間不足,資料庫最終會終止操作。
而可恢複的空間分配功能可以使得這類操作掛起,等待DBA去處理,等成功處理之後大型資料庫操作自動回復,這樣就避免了這類棘手問題,節省了時間。

1.2 配置可恢複的空間分配

相關參數和用法:

--參數resumable_timeoutshow parameter resumable_timeout--執行個體層級啟用resumablealter system set resumable_timeout = 7200;--執行個體層級禁用resumablealter system set resumable_timeout = 0;--賦權resumable許可權給某個使用者grant resumable to jingyu;--會話層級修改--啟用resumablealter session enable resumable;--設定掛起時間長度alter session enable resumable timeout 144000;--設定名稱alter session enable resumable name 'Create Big Index';--禁用resumablealter session disable resumable;--查詢DBA_RESUMABLE瞭解掛起語句的詳細資料set linesize 140col name for a40col error_msg for a30select USER_ID, SESSION_ID, INSTANCE_ID, STATUS, NAME, ERROR_MSG from dba_resumable;

實驗-配置使用當前會話的可恢複的空間分配:

--如果資料表空間不足,建立表會直接失敗SQL> show userUSER is "JINGYU"SQL> create table t_s1 as select * from dba_objects;create table t_s1 as select * from dba_objects*ERROR at line 1:ORA-01652: unable to extend temp segment by 128 in tablespace DBS_D_JINGYU--如果啟用session的resumable,再建立表就會掛起操作SQL> alter session enable resumable timeout 7200;Session altered.SQL> create table t_s1 as select * from dba_objects;...這裡長時間掛起--此時我們從警示日誌中可以看到對應的日誌資訊,操作被掛起:Wed Jan 13 09:51:55 2016statement in resumable session 'User JINGYU(99), Session 62, Instance 1' was suspended due to    ORA-01652: unable to extend temp segment by 128 in tablespace DBS_D_JINGYU--擴充資料表空間SQL> alter tablespace DBS_D_JINGYU add datafile size 30M;Tablespace altered.--此時警示日誌資訊可以看到操作繼續執行:Wed Jan 13 10:01:12 2016statement in resumable session 'User JINGYU(99), Session 62, Instance 1' was resumedCompleted: alter tablespace DBS_D_JINGYU add datafile size 30M autoextend on--再去看剛剛掛起的建表語句已經執行成功SQL> create table t_s1 as select * from dba_objects;Table created.--禁用當前會話的resumablealter session disable resumable;
1.3 使用可恢複的空間分配功能
--觸發器基本結構如下,需要根據具體需求來完善create or replace trigger resumable_notify  after suspend on databasedeclare  -- variables, if requiredbegin  -- check DBA_RESUMABLE for user ID, type of  -- object, then send e-mail  dbms_resumable.space_error_info(. . .);  if object_type = 'TABLE' and object_owner = 'HR' then    -- give DBA 2 hours to resolve    dbms_resumable.set_timeout(7200);    utl_mail.send('DBA@company.com',. . .);  else    dbms_resumable.abort(. . .);  end if;end;
2.可移動資料表空間

使用Data Pump匯出資料表空間中對象的中繼資料,將組成資料表空間的資料檔案複製到目的資料庫,然後把資料表空間的中繼資料匯入到目的資料庫中。

2.1 配置可移動資料表空間

在平台間傳輸資料,源平台和目的平台必須是Oracle支援的平台列表中的成員。

2.1.1 確定相容性需求

Oracle資料庫的功能相容性由COMPATIBLE初始化參數進行控制,此參數啟用或禁用資料庫中的某些功能。建立可移動資料表空間集合時,Oracle將確定目標資料庫的最低相容性層級,並將相應值儲存在可移動資料集的中繼資料中。從Oracle Database 11g開始,不管對於哪種目標平台,始終可以將資料表空間移動到擁有相同或更高相容性層級的另一個資料庫中。
另外,兩個資料庫必須使用相同的字元集。

2.1.2 確定位元組序要求
--查詢可移動資料表空間的所有支援平台及其ENDIAN_FORMAT:SQL> select platform_id, platform_name, endian_format from v$transportable_platform order by 3,1;PLATFORM_ID PLATFORM_NAME                            ENDIAN_FORMAT----------- ---------------------------------------- ------------------------------          1 Solaris[tm] OE (32-bit)                  Big          2 Solaris[tm] OE (64-bit)                  Big          3 HP-UX (64-bit)                           Big          4 HP-UX IA (64-bit)                        Big          6 AIX-Based Systems (64-bit)               Big          9 IBM zSeries Based Linux                  Big         16 Apple Mac OS                             Big         18 IBM Power Based Linux                    Big          5 HP Tru64 UNIX                            Little          7 Microsoft Windows IA (32-bit)            Little          8 Microsoft Windows IA (64-bit)            Little         10 Linux IA (32-bit)                        Little         11 Linux IA (64-bit)                        Little         12 Microsoft Windows x86 64-bit             Little         13 Linux x86 64-bit                         Little         15 HP Open VMS                              Little         17 Solaris Operating System (x86)           Little         19 HP IA Open VMS                           Little         20 Solaris Operating System (x86-64)        Little         21 Apple Mac OS (x86-64)                    Little20 rows selected.--查詢當前平台的位元組序格式select PLATFORM_NAME my_platform, ENDIAN_FORMAT my_endian_format from v$transportable_platform join v$database using(platform_name);SQL> select PLATFORM_NAME my_platform, ENDIAN_FORMAT my_endian_format      2  from v$transportable_platform  3  join v$database using(platform_name);MY_PLATFORM                    MY_ENDIAN_FORMAT------------------------------ ------------------------------------------Linux x86 64-bit               Little
2.2 傳輸資料表空間

傳輸資料表空間核心步驟:
1)來源資料庫上的表空��設為唯讀模式;
2)來源資料庫上提取資料表空間中繼資料;
3)如果源和目的的位元組序格式不同,轉換資料表空間內容;
4)拷貝資料表空間資料檔案以及資料表空間中繼資料到目的資料庫;
5)目的資料庫匯入資料表空間中繼資料;
6)來源資料庫和目的資料庫的資料表空間設定為讀寫入模式。

--使用者的預設資料表空間和預設暫存資料表空間select username, DEFAULT_TABLESPACE, TEMPORARY_TABLESPACE from user_users;--使用者用到的資料表空間select tablespace_name from user_tables unionselect tablespace_name from user_tab_partitions unionselect tablespace_name from user_indexes unionselect tablespace_name from user_ind_partitions;
2.2.1 使用EM傳輸資料表空間

web圖形化介面操作,
1.點擊資料移動 -> 傳輸資料表空間 -> 產生可傳輸的資料表空間集,然後按提示一步步產生;
2.在目的地資料庫 點擊資料移動 -> 傳輸資料表空間 -> 整合現有可傳輸資料表空間集,然後按提示一步步整合在目的資料庫中。
我這裡實驗在產生可傳輸的資料表空間集時報錯:ORA-02097,ORA-19529。

--根據MOS文檔:Received ORA-19529 Attempting To Do A Transportable Tablespace Export Through OEM (文檔 ID 2073402.1)ORA-02097: parameter cannot be modified because specified value is invalidORA-19529: Pattern /home/kqualls/transport/epsdev/o1_mf_ekb_cons_b6qc1hbm_.dbf in initialization parameter db_file_name_convert has an Oracle Managed Files file name.--原因:EM Cloud Control 12c does not support conversion of OMF files. Currently only user managed files are supported using the EM feature.   There is an enhancement logged, Bug 21233808 - Cloud Control TTS generates invalid db_file_name_convert command ORA-02097--解決:Create RMAN Job in EM Cloud Control Job system, enter command line script commands there. Using the RMAN Job in the EM Job system will allow the process to use the database parameters to convert the datafiles rather than using the EM perl scripts that don't support OMF files.

PS:即使沒有問題,一般生產環境傳輸資料表空間也不採用EM,因為很多生產環境都沒有安裝EM,或者複雜的網路環境因素導致不方便使用EM。還是手動使用SQL傳輸資料表空間更加靠譜。

2.2.2 使用SQL傳輸資料表空間

參考:

  • Oracle使用SQL傳輸資料表空間
3.Oracle段收縮功能

參考:

  • Oracle段收縮功能
4.Oracle資料庫資源管理

參考:

  • Oracle資料庫資源管理

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.