Oracle管理磁盘空间和资源


1.可恢复的空间分配

1.1 了解可恢复的空间分配

一般情况,我们发出一个大型数据库操作,比如创建大表索引,如果表空间不足,数据库最终会终止操作。
而可恢复的空间分配功能可以使得这类操作挂起,等待DBA去处理,等成功处理之后大型数据库操作自动恢复,这样就避免了这类棘手问题,节省了时间。

1.2 配置可恢复的空间分配

相关参数和用法:

--参数resumable_timeout
show parameter resumable_timeout
--实例级别启用resumable
alter system set resumable_timeout = 7200;
--实例级别禁用resumable
alter system set resumable_timeout = 0;
--赋权resumable权限给某个用户
grant resumable to jingyu;

--会话级别修改
--启用resumable
alter session enable resumable;
--设定挂起时长
alter session enable resumable timeout 144000;
--设定名称
alter session enable resumable name 'Create Big Index';
--禁用resumable
alter session disable resumable;

--查询DBA_RESUMABLE了解挂起语句的详细信息
set linesize 140
col name for a40
col error_msg for a30
select USER_ID, SESSION_ID, INSTANCE_ID, STATUS, NAME, ERROR_MSG from dba_resumable;

实验-配置使用当前会话的可恢复的空间分配:

--如果表空间不足,创建表会直接失败
SQL> show user
USER 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 2016
statement 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 2016
statement in resumable session 'User JINGYU(99), Session 62, Instance 1' was resumed
Completed: alter tablespace DBS_D_JINGYU add datafile size 30M autoextend on
--再去看刚刚挂起的建表语句已经执行成功
SQL> create table t_s1 as select * from dba_objects;
Table created.
--禁用当前会话的resumable
alter session disable resumable;

1.3 使用可恢复的空间分配功能

--触发器基本结构如下,需要根据具体需求来完善
create or replace trigger resumable_notify
  after suspend on database
declare
  -- variables, if required
begin
  -- 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)                    Little

20 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 union
select tablespace_name from user_tab_partitions union
select tablespace_name from user_indexes union
select 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 invalid
ORA-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数据库资源管理

本文永久更新链接地址

相关内容

    暂无相关文章