温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Oracle可传输表空间怎么理解

发布时间:2021-12-07 11:29:46 来源:亿速云 阅读:133 作者:iii 栏目:建站服务器

这篇文章主要讲解了“Oracle可传输表空间怎么理解”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Oracle可传输表空间怎么理解”吧!

我们在Oracle环境中,有很多进行数据备份和移植手段,如exp/impexpdp/impdprman等。在这些方法中,可传输表空间(Transportable Tablespace)一直是传统意义上最快数据移植的技术手段。理想情况下,Transportable Tablespace可以实现近似网络直传的速率特点。

 

1Transportable Tablespace概述

 

其他传统意义上的备份迁移手段,大都是遵循“抽取-传输-还原”的模式。以expdp为例,Oracle使用专门的内部调度作业,将需要导出的数据(Used Block)转化为dmp格式文件进行存储保存。之后,通过网络进行传输到Target Envionment,最后再还原到新环境上。这种模式的加速优化,主要体现在抽取和还原上,如使用并行等手段。

 

Transportable Tablespace完全不是这样的概念。如果比喻的话,它类似一种Portable/Plugin的理念。相同平台、字符集的表空间,完全可以将数据文件直接拷贝到Target EnvironmentOracle层面只需要让数据字典知道这些数据的metadata就可以了。

 

相对于其他手段,Transportable Tablespace最大的好处就在于不需要进行繁复的抽取和还原过程,而且对中间环境的空间要求很小。下面通过一系列的实验来进行演示。

 

2、环境准备和前提条件

 

Oracle Transportable Tablespace(以下简称为TTS)出现的很早。传统的TTS有三个层面基础限制,分别为:

 

ü  表空间内容self contained。我们一次性导出的表空间(一个或者多个),不能在其他表空间中存在依赖对象。比如,我们常常将一个数据表数据和索引分布在不同的表空间上,这样如果我们使用Transportable Tablespace,就要求必须将这些表空间一次性全部导出;

ü  SourceTarget DBCharacter SetNational Character Set必须完全相同;

ü  操作系统Source Target DB要求兼容。注意:在10g以上版本,这个限制已经取消;

 

我们会在下面更加直观的介绍这些约束和检查方法。由于笔者环境的限制,一些实验只能在一台服务器上进行。具体实验选择Oracle 11gR2

 

 

SQL> select * from v$version;

BANNER

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

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

PL/SQL Release 11.2.0.1.0 - Production

CORE        11.2.0.1.0         Production

 

--构造两个实验表空间

SQL> create tablespace ttstbl datafile size 10m autoextend on

  2  extent management local uniform. size 1m

  3  segment space management auto;

Tablespace created

 

SQL> create tablespace ttsind datafile size 10m autoextend on

  2  extent management local uniform. size 1m

  3  segment space management auto;

Tablespace created

 

--测试用户

SQL> create user test identified by test default tablespace ttstbl;

User created

 

SQL> grant resource, connect to test;

Grant succeeded

 

SQL> grant select_catalog_role to test;

Grant succeeded

 

 

使用test用户在表空间中创建一些对象。

 

 

SQL> conn test/test@ora11gp;

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0

Connected as test

 

SQL> create table t tablespace ttstbl as select * from dba_objects;

Table created

 

SQL> create index idx_t_id on t(object_id) tablespace ttsind;

Index created

 

 

3Pre-Condition Check

 

作为先决条件,首选确定Source数据库的字符集信息。

 

 

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

VALUE

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

AL32UTF8

 

SQL> select value from nls_database_parameters where parameter='NLS_NCHAR_CHARACTERSET';

VALUE

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

AL16UTF16

 

 

希望导出新创建的表空间ttsindttstbl

 

 

SQL> select file_name, tablespace_name from dba_data_files where tablespace_name like 'TTS%';

 

FILE_NAME                                                                        TABLESPACE_NAME

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

/u01/app/oradata/ORA11G/datafile/o1_mf_ttstbl_8bmyjf3w_.dbf                      TTSTBL

/u01/app/oradata/ORA11G/datafile/o1_mf_ttsind_8bmyjz69_.dbf                      TTSIND

 

 

[oracle@bsplinux datafile]$ ls -l

total 2095500

(篇幅原因,省略部分内容)

-rw-r----- 1 oracle oinstall  10493952 Nov 19 18:04 o1_mf_ttsind_8bmyjz69_.dbf

-rw-r----- 1 oracle oinstall  20979712 Nov 19 17:59 o1_mf_ttstbl_8bmyjf3w_.dbf

-rw-r----- 1 oracle oinstall 267395072 Nov 19 18:13 o1_mf_undotbs1_7vpyc2py_.dbf

-rw-r----- 1 oracle oinstall  11804672 Nov 19 17:29 o1_mf_users_7vpyc2xd_.dbf

 

 

传统的约束条件中,操作系统平台OS是使用TTS不能回避的因素。Oracle将支持平台划分为两个大类型BigLittle,同平台之间可以进行自由表空间移植,异平台之间不允许进行移植。注意:这个限制在Oracle 10g之后被打破。具体我们后面详细介绍。

 

我们可以通过查询v$transportable_platform来确定系统之间是否兼容。

 

 

SQL> col platform_name for a30;

SQL> select platform_name, ENDIAN_FORMAT from v$transportable_platform;

 

PLATFORM_NAME                  ENDIAN_FORMAT

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

Solaris[tm] OE (32-bit)        Big

Solaris[tm] OE (64-bit)        Big

Microsoft Windows IA (32-bit)  Little

Linux IA (32-bit)              Little

AIX-Based Systems (64-bit)     Big

HP-UX (64-bit)                 Big

HP Tru64 UNIX                  Little

HP-UX IA (64-bit)              Big

Linux IA (64-bit)              Little

HP Open VMS                    Little

Microsoft Windows IA (64-bit)  Little

IBM zSeries Based Linux        Big

Linux x86 64-bit               Little

Apple Mac OS                   Big

Microsoft Windows x86 64-bit   Little

Solaris Operating System (x86) Little

IBM Power Based Linux          Big

HP IA Open VMS                 Little

Solaris Operating System (x86- Little

64)                            

Apple Mac OS (x86-64)          Little

 

20 rows selected

 

 

对于自己的数据库,v$database视图中可以查询自己的平台情况信息。

 

 

SQL> select PLATFORM_ID , PLATFORM_NAME from v$database;

 

PLATFORM_ID PLATFORM_NAME

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

         10 Linux IA (32-bit)

 

 

确定平台兼容之后,我们需要确定一次移植的表空间之间是否“Self Contained”。Oracle提供的dbms_tts包方法来进行验证。

 

 

SQL> exec dbms_tts.transport_set_check('ttstbl, ttsind',true);

PL/SQL procedure successfully completed

 

SQL> select * from transport_set_violations;

 

VIOLATIONS

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

 

 

如果验证出现错误,我们可以在transport_set_violations中查询到提示信息。只有解决了self contained问题,才能继续下面的步骤。

 

4、环境数据导出

 

为了控制变化,我们需要将表空间设置为只读。具体语句为:alter tablespace xxx read only

 

 

SQL> select tablespace_name, status from dba_tablespaces where tablespace_name like 'TTS%';

 

TABLESPACE_NAME                STATUS

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

TTSIND                         READ ONLY

TTSTBL                         READ ONLY

 

 

Oracle TTS需要使用exp/expdp将表空间的元数据Metadata信息导出为dmp文件,用于描述表空间信息。注意,这个过程时间很短,而且生成的dmp文件通常很小。

 

 

[root@bsplinux ~]# cd /

[root@bsplinux /]# mkdir transtts

[root@bsplinux /]# chown -R oracle:oinstall transtts/

[root@bsplinux /]# ls -l | grep transtts

drwxr-xr-x   2 oracle   oinstall  4096 Nov 19 18:19 transtts

[root@bsplinux /]#

 

 

Exp支持了TTS工作方法。

 

 

[oracle@bsplinux transtts]$ exp userid=\"/ as sysdba\" transport_tablespace=y tablespaces=ttstbl,ttsind file=ttsdmp.dmp log=res.log statistics=none

 

Export: Release 11.2.0.1.0 - Production on Mon Nov 19 19:32:14 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set

Note: table data (rows) will not be exported

About to export transportable tablespace metadata...

For tablespace TTSTBL ...

. exporting cluster definitions

. exporting table definitions

. . exporting table                              T

For tablespace TTSIND ...

. exporting cluster definitions

. exporting table definitions

. exporting referential integrity constraints

. exporting triggers

. end transportable tablespace metadata export

Export terminated successfully without warnings.

 

 

之后,我们只需要直接将数据文件拷贝出来。

 

 

SQL> select 'cp '||file_name ||' /transtts' from dba_data_files where tablespace_name like 'TTS%';

 

'CP'||FILE_NAME||'/TRANSTTS'

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

cp /u01/app/oradata/ORA11G/datafile/o1_mf_ttstbl_8bmyjf3w_.dbf /transtts

cp /u01/app/oradata/ORA11G/datafile/o1_mf_ttsind_8bmyjz69_.dbf /transtts

 

 

[oracle@bsplinux transtts]$ cp /u01/app/oradata/ORA11G/datafile/o1_mf_ttstbl_8bmyjf3w_.dbf /transtts

cp /u01/app/oradata/ORA11G/datafile/o1_mf_ttsind_8bmyjz69_.dbf /transtts

[oracle@bsplinux transtts]$ cp /u01/app/oradata/ORA11G/datafile/o1_mf_ttsind_8bmyjz69_.dbf /transtts

[oracle@bsplinux transtts]$

 

 

 

[oracle@bsplinux transtts]$ ls -l

total 30796

-rw-r----- 1 oracle oinstall 10493952 Nov 19 19:35 o1_mf_ttsind_8bmyjz69_.dbf

-rw-r----- 1 oracle oinstall 20979712 Nov 19 19:35 o1_mf_ttstbl_8bmyjf3w_.dbf

-rw-r--r-- 1 oracle oinstall      724 Nov 19 19:33 res.log

-rw-r--r-- 1 oracle oinstall    16384 Nov 19 19:33 ttsdmp.dmp

 

 

/transtts目录中,保存了所有需要还原数据库的信息。

 

5、数据环境恢复

 

我们需要将数据文件通过FTP/SFTP传输到目标数据库服务器上。笔者先将数据环境还原,因为使用的是相同的数据库。

 

 

SQL> drop tablespace ttstbl including contents and datafiles;

Tablespace dropped

 

SQL> drop tablespace ttsind including contents and datafiles;

Tablespace dropped

 

SQL> select file_name from dba_data_files where tablespace_name like 'TTS%';

FILE_NAME

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

 

 

Source数据库已经没有TTS表空间了。下面,我们将数据文件拷贝到新位置,并且导入Metadata信息。

 

 

[oracle@bsplinux transtts]$ cp o1_mf_ttstbl_8bmyjf3w_.dbf /u01/app/oradata/ORA11G/datafile/

[oracle@bsplinux transtts]$ cp o1_mf_ttsind_8bmyjz69_.dbf /u01/app/oradata/ORA11G/datafile/

 

[oracle@bsplinux datafile]$ ls -l

total 2095500

-rw-r----- 1 oracle oinstall  10493952 Jul  3 03:48 mytesttbl01.dbf

-rw-r----- 1 oracle oinstall  10493952 Jul  3 03:48 mytesttbl02.dbf

-rw-r----- 1 oracle oinstall 104865792 Nov 19 17:29 o1_mf_rman_ts_87bx5kcg_.dbf

-rw-r----- 1 oracle oinstall 838868992 Nov 19 19:46 o1_mf_sysaux_7vpyc2hb_.dbf

-rw-r----- 1 oracle oinstall 807411712 Nov 19 19:43 o1_mf_system_7vpyc1x7_.dbf

-rw-r----- 1 oracle oinstall  60825600 Nov 19 18:02 o1_mf_temp_7vpz05do_.tmp

-rw-r----- 1 oracle oinstall  10493952 Nov 19 19:47 o1_mf_ttsind_8bmyjz69_.dbf

-rw-r----- 1 oracle oinstall  20979712 Nov 19 19:46 o1_mf_ttstbl_8bmyjf3w_.dbf

-rw-r----- 1 oracle oinstall 267395072 Nov 19 19:47 o1_mf_undotbs1_7vpyc2py_.dbf

-rw-r----- 1 oracle oinstall  11804672 Nov 19 17:29 o1_mf_users_7vpyc2xd_.dbf

 

 

Imp命令导入。

 

 

[oracle@bsplinux transtts]$ imp userid=\'/ as sysdba\' file=ttsdmp.dmp transport_tablespace=y tablespaces=ttsind,ttstbl datafiles=/u01/app/oradata/ORA11G/datafile/o1_mf_ttstbl_8bmyjf3w_.dbf,/u01/app/oradata/ORA11G/datafile/o1_mf_ttsind_8bmyjz69_.dbf

 

Import: Release 11.2.0.1.0 - Production on Mon Nov 19 19:51:25 2012

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

Export file created by EXPORT:V11.02.00 via conventional path

About to import transportable tablespace(s) metadata...

import done in AL32UTF8 character set and AL16UTF16 NCHAR character set

. importing SYS's objects into SYS

. importing SYS's objects into SYS

. importing TEST's objects into TEST

. . importing table                            "T"

. importing SYS's objects into SYS

Import terminated successfully without warnings.

[oracle@bsplinux transtts]$

 

 

导入元数据后,Oracle中可以确定导入的表空间了。

 

 

SQL> select file_name,tablespace_name from dba_data_files where tablespace_name like 'TTS%';

 

FILE_NAME                                                                        TABLESPACE_NAME

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

/u01/app/oradata/ORA11G/datafile/o1_mf_ttsind_8bmyjz69_.dbf                      TTSIND

/u01/app/oradata/ORA11G/datafile/o1_mf_ttstbl_8bmyjf3w_.dbf                      TTSTBL

 

SQL> conn test/test@ora11gp

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0

Connected as test

 

SQL> select count(*) from t;

 

  COUNT(*)

----------

     72348

 

注意,导入后的表空间还是read only状态,需要开启。

 

SQL> alter tablespace ttsind read write;

Tablespace altered

 

SQL> alter tablespace ttstbl read write;

Tablespace altered

感谢各位的阅读,以上就是“Oracle可传输表空间怎么理解”的内容了,经过本文的学习后,相信大家对Oracle可传输表空间怎么理解这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI