什么行使Direct NFS克隆数据库

CloneDB是Oracle 11.2.0.3推出的一项新特性,它使用的了11g新引入的Direct
NFS。它一贯运用对象数据库的备份,无需将备份COPY到克隆环境下,使得二个备份能够仿造多少个例外用途的数据库。它同时选拔了copy-on-write技术,使得备份中只有被改动了的block才会被利用到克隆数据库中,十分的大的节约了克隆数据库的空间,并升级了数据Cook隆的快慢。

下边对该项天性开始展览了测试,共涉及三台服务器,采纳的均是30个人汉兰达HEL
6.3操作系统,数据库版本11.2.0.4。

NFS服务器:
   主机名:node3.being.com
   IP: 192.168.2.13
   共享路径:/u01
生产数据库:
   主机名: node1.being.com
   IP: 192.168.2.11
   ORACLE_HOME: /u01/app/oracle/product/11.2.0.4/db_1
   ORACLE_SID:prod
   挂载点:/backup/prod/
克隆数据库:
   主机名:node2.being.com
   IP:192.168.2.12
   ORACLE_HOME:/u01/app/oracle/product/11.2.0.4/db_1
   ORACLE_SID:orcl
   挂载点:/prod/backup

一、准备NFS环境

先是查看一下node3的磁盘景况

[root@node3 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             5.8G  3.9G  1.6G  72% /
tmpfs                 504M     0  504M   0% /dev/shm
/dev/sda4              20G  172M   19G   1% /u01   

在此间,打算将/u01作为NFS磁盘共享出去。

在NFS Server的主配置文件中/etc/exports添加以下内容:

/u01 *(rw,no_root_squash)

在此处,注意/u01的权位,刚开头/u01暗中认可的是755权力,node1挂载后,无法制造文件,报“Permission
denied”。

修改/u01的权限

[root@node3 ~]# chmod 757 /u01/

重启rpcbind和nfs服务

[root@node3 ~]# /etc/init.d/rpcbind restart
Stopping rpcbind:                                          [FAILED]
Starting rpcbind:                                          [  OK  ]

[root@node3 ~]# /etc/init.d/nfs restart
Shutting down NFS daemon:                                  [FAILED]
Shutting down NFS mountd:                                  [FAILED]
Shutting down NFS quotas:                                  [FAILED]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]

查阅配置是或不是中标

[root@node3 ~]# showmount -e 192.168.2.13
Export list for 192.168.2.13:
/u01 *

将rpcbind和nfs服务设为开机自运转

[root@node3 ~]# chkconfig rpcbind on
[root@node3 ~]# chkconfig nfs on

贰 、在生产数据库上挂载NFS文件系统

以root身份登录,创立备份目录

[root@node1 ~]# mkdir /backup/prod

挂载node3提供的nfs磁盘

[root@node1 ~]# showmount -e 192.168.2.13
Export list for 192.168.2.13:
/u01 *
[root@node1 ~]# mount 192.168.2.13:/u01 /backup/prod/
[root@node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             7.7G  3.6G  3.8G  49% /
tmpfs                 400M  184M  217M  46% /dev/shm
/dev/sda1             194M   27M  158M  15% /boot
/dev/sda4              28G   11G   16G  41% /u01
192.168.2.13:/u01      20G  172M   19G   1% /backup/prod

挂载后,无法给/backup/prod修改文件属主和属组,譬如作者想将该目录设置为oracle用户专享的,结果如下:

[root@node1 ~]# chown oracle.oinstall /backup/prod/
chown: changing ownership of `/backup/prod/': Invalid argument

新生察觉实际无此须要,node第11中学/backup/prod的权柄和node3中的/u01权限是相呼应的,皆以757。作者以oracle用户的身份在该目录下开创文件,文件的属主和属组就分别是oracle和oinstall。

设置为开机自动挂载

在/etc/rc.local添加以下内容:

mount 192.168.2.13:/u01 /backup/prod/

三 、在仿制数据库上挂载NFS文件系统

以root身份登录,成立备份目录,名字随意

[root@node2 ~]# mkdir -p /prod/backup

挂载node3提供的NFS共享盘

[root@node2 ~]# mount 192.168.2.13:/u01 /prod/backup/
[root@node2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             9.7G  6.2G  3.0G  68% /
tmpfs                 400M     0  400M   0% /dev/shm
/dev/sda1             194M   27M  158M  15% /boot
/dev/sdb               20G  4.2G   15G  23% /u01
192.168.2.13:/u01      20G  172M   19G   1% /prod/backup

同一设置开机自动挂载

在/etc/rc.local中加上以下内容:

mount 192.168.2.13:/u01 /prod/backup/

四 、克隆数据库上启用Direct NFS

登录oracle账户,新建$ORACLE_HOME/dbs/oranfstab文件,内容如下:

[oracle@node2 ~]$ cat $ORACLE_HOME/dbs/oranfstab
server:node3.being.com
path:192.168.2.13
export:/u01
mount:/prod/backup

修改libodm11.so库文件的链接对象

[oracle@node2 lib]$ mv libodm11.so libodm11.so.bak
[oracle@node2 lib]$ ln -s libnfsodm11.so libodm11.so

伍 、备份生产数据库

支撑二种备份形式:在线热备(类似于alter database begin backup)、offline
备份(需关闭数据库)、rman “BACKUP AS COPY”(不帮衬rman备份集)

在此处,大家选取rman备份

以oracle身份登录node1

[oracle@node1 ~]$ rman target /
RMAN> sql 'alter database begin backup';
RMAN> backup as copy database format '/backup/prod/%U';
RMAN> sql 'alter database end backup';

备份完成后,查看/backup/prod中的备份文件

[oracle@node1 ~]$ ll /backup/prod/
total 1294792
-rw-r-----. 1 oracle asmadmin     98304 Apr 24 00:26 0cq553i6_1_1
-rw-r-----. 1 oracle asmadmin   9748480 Apr 24 00:26 cf_D-PROD_id-289579616_0aq553hp
-rw-r-----. 1 oracle asmadmin 513810432 Apr 24 00:26 data_D-PROD_I-289579616_TS-SYSAUX_FNO-2_08q553gd
-rw-r-----. 1 oracle asmadmin 765468672 Apr 24 00:25 data_D-PROD_I-289579616_TS-SYSTEM_FNO-1_07q553dp
-rw-r-----. 1 oracle asmadmin  31465472 Apr 24 00:26 data_D-PROD_I-289579616_TS-UNDOTBS1_FNO-3_09q553hj
-rw-r-----. 1 oracle asmadmin   5251072 Apr 24 00:26 data_D-PROD_I-289579616_TS-USERS_FNO-4_0bq553i5
drwx------. 2 root   root         16384 Apr 23 19:45 lost+found

其中cf_D-PROD_id-289579616_0aq553hp为控制文件的备份

六 、为克隆数据库创制pfile

登录生产数据库

[oracle@node1 ~]$ sqlplus / as sysdba

生成pfile

SQL> create pfile='/backup/prod/pfile.ora' from spfile;

修改参数文件,除将全体涉及到prod的地点改为orcl外,同时新增了三个参数CLONEDB=TRUE,这些是少不了的,最终参数文件内容如下:

[oracle@node1 ~]$ cat /backup/prod/pfile.ora 
orcl.__db_cache_size=83886080
orcl.__java_pool_size=4194304
orcl.__large_pool_size=8388608
orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=125829120
orcl.__sga_target=188743680
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=83886080
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4353687552
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.memory_target=314572800
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
CLONEDB=TRUE

在仿制数据库中新建参数文件中涉嫌的目录

[oracle@node2 admin]$ mkdir -p /u01/app/oracle/admin/orcl/adump
[oracle@node2 admin]$ mkdir -p /u01/app/oracle/oradata/orcl/
[oracle@node2 admin]$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl

7、克隆数据库

ORACLE官方文档中提供了两种情势,一种是应用oracle自个儿提供的剧本,3个是手动成立。

在此处,我们选择脚本情势,通过脚本执行进度中的输出,相比ORACLE官方文书档案,大家能够发现互相其实是平等的,只不过手动创立所需求的通令写到脚本里面去了。

先是在仿制数据库所在的主机上安装环境变量

[oracle@node2 ~]$ export MASTER_COPY_DIR=/prod/backup
[oracle@node2 ~]$ export CLONE_FILE_CREATE_DEST=/u01/app/oracle/oradata/orcl
[oracle@node2 ~]$ export CLONEDB_NAME=orcl

其中MASTER_COPY_DILX570指的是备份所在的目录,CLONE_FILE_CREATE_DEST指的是数据文件、日志文件、控制文件所在的目录,CLONEDB_NAME内定数量库名

实践数据库提供的perl脚本,关于脚本所在的目录及其实施的措施,我们来看看官方的表明:

Oracle 1

因为本身的数据库版本为11.2.0.4,故直接COPY到home目录下

[oracle@node2 ~]$ cp /u01/app/oracle/product/11.2.0.1/db_1/rdbms/install/clonedb.pl ~

实行脚本

[oracle@node2 ~]$ perl clonedb.pl /prod/backup/pfile.ora crtdb.sql dbren.sql

在/home/oracle下会生成多少个文件,crtdb.sql和dbren.sql

登录数据库,执行crtdb.sql

[oracle@node2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Fri Apr 24 18:26:46 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> @crtdb.sql
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL> 
SQL> STARTUP NOMOUNT PFILE=/u01/app/oracle/oradata/orcl/initorcl.ora
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1364340 bytes
Variable Size             272633484 bytes
Database Buffers           33554432 bytes
Redo Buffers                6307840 bytes
SQL> CREATE CONTROLFILE REUSE SET DATABASE orcl RESETLOGS
  2      MAXLOGFILES 32
  3      MAXLOGMEMBERS 2
  4      MAXINSTANCES 1
  5      MAXLOGHISTORY 908
  6  LOGFILE
  7    GROUP 1 '/u01/app/oracle/oradata/orcl/orcl_log1.log' SIZE 100M BLOCKSIZE 512,
  8    GROUP 2 '/u01/app/oracle/oradata/orcl/orcl_log2.log' SIZE 100M BLOCKSIZE 512
  9  DATAFILE
 10  '/prod/backup/0cq553i6_1_1',
 11  '/prod/backup/cf_D-PROD_id-289579616_0aq553hp',
 12  '/prod/backup/data_D-PROD_I-289579616_TS-SYSAUX_FNO-2_08q553gd',
 13  '/prod/backup/data_D-PROD_I-289579616_TS-SYSTEM_FNO-1_07q553dp',
 14  '/prod/backup/data_D-PROD_I-289579616_TS-UNDOTBS1_FNO-3_09q553hj',
 15  '/prod/backup/data_D-PROD_I-289579616_TS-USERS_FNO-4_0bq553i5',
 16  '/prod/backup/lost+found',
 17  '/prod/backup/pfile.ora'
 18  CHARACTER SET WE8DEC;
CREATE CONTROLFILE REUSE SET DATABASE orcl RESETLOGS
*
ERROR at line 1:
ORA-01503: CREATE CONTROLFILE failed
ORA-00058: DB_BLOCK_SIZE must be 16384 to mount this database (not 8192)

报以上错误,再来看看datafile上面包车型客车公文,然后它把/prod/backup上边包车型地铁有所的文件都包括内部了,包罗控制文件的备份和lost+found文件,而那并不是数据文件,关闭数据库,删除该目录下的其他文件,将pfile
move到/home/oracle下,重新履行clonedb.pl脚本

SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@node2 ~]$ cd /prod/backup/
[oracle@node2 backup]$ ls
0cq553i6_1_1
cf_D-PROD_id-289579616_0aq553hp
data_D-PROD_I-289579616_TS-SYSAUX_FNO-2_08q553gd
data_D-PROD_I-289579616_TS-SYSTEM_FNO-1_07q553dp
data_D-PROD_I-289579616_TS-UNDOTBS1_FNO-3_09q553hj
data_D-PROD_I-289579616_TS-USERS_FNO-4_0bq553i5
lost+found
pfile.ora
[oracle@node2 backup]$ rm 0cq553i6_1_1 
[oracle@node2 backup]$ rm cf_D-PROD_id-289579616_0aq553hp
[oracle@node2 backup]$ rm -rf lost+found/
[oracle@node2 backup]$ mv pfile.ora ~
[oracle@node2 backup]$ cd ~
[oracle@node2 ~]$ perl clonedb.pl pfile.ora crtdb.sql dbren.sql

再也履行crtdb.sql脚本,结果如下:

[oracle@node2 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Apr 27 18:13:39 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> @crtdb.sql
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL> 
SQL> STARTUP NOMOUNT PFILE=/u01/app/oracle/oradata/orcl/initorcl.ora
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1364340 bytes
Variable Size             272633484 bytes
Database Buffers           33554432 bytes
Redo Buffers                6307840 bytes
SQL> CREATE CONTROLFILE REUSE SET DATABASE orcl RESETLOGS
  2      MAXLOGFILES 32
  3      MAXLOGMEMBERS 2
  4      MAXINSTANCES 1
  5      MAXLOGHISTORY 908
  6  LOGFILE
  7    GROUP 1 '/u01/app/oracle/oradata/orcl/orcl_log1.log' SIZE 100M BLOCKSIZE 512,
  8    GROUP 2 '/u01/app/oracle/oradata/orcl/orcl_log2.log' SIZE 100M BLOCKSIZE 512
  9  DATAFILE
 10  '/prod/backup/data_D-PROD_I-289579616_TS-SYSAUX_FNO-2_0pq5eur7',
 11  '/prod/backup/data_D-PROD_I-289579616_TS-SYSTEM_FNO-1_0oq5eunu',
 12  '/prod/backup/data_D-PROD_I-289579616_TS-UNDOTBS1_FNO-3_0rq5euss',
 13  '/prod/backup/data_D-PROD_I-289579616_TS-USERS_FNO-4_0qq5eusl'
 14  CHARACTER SET WE8DEC;

Control file created.

执行dbren.sql脚本

SQL> @dbren.sql
SQL> declare
  2  begin
  3  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-SYSAUX_FNO-2_0pq5eur7' , '/u01/app/oracle/oradata/orcl/ora_data_orcl0.dbf');
  4  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-SYSTEM_FNO-1_0oq5eunu' , '/u01/app/oracle/oradata/orcl/ora_data_orcl1.dbf');
  5  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-UNDOTBS1_FNO-3_0rq5euss' , '/u01/app/oracle/oradata/orcl/ora_data_orcl2.dbf');
  6  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-USERS_FNO-4_0qq5eusl' , '/u01/app/oracle/oradata/orcl/ora_data_orcl3.dbf');
  7  end;
  8  /

PL/SQL procedure successfully completed.

SQL> show errors;
No errors.
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01190: control file or data file 1 is from before the last RESETLOGS
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/ora_data_orcl1.dbf'


SQL> drop tablespace TEMP;
drop tablespace TEMP
*
ERROR at line 1:
ORA-01109: database not open


SQL> create temporary tablespace TEMP;
create temporary tablespace TEMP
*
ERROR at line 1:
ORA-01109: database not open

下边大家来看望八个检查点:

  1. 系统检查点

    SQL> select checkpoint_change# from v$database;

    CHECKPOINT_CHANGE#

             791020
    

    1 row selected.

2. 数据文件检查点 

SQL> select file#,checkpoint_change#,last_change# from v$datafile;

     FILE# CHECKPOINT_CHANGE# LAST_CHANGE#
---------- ------------------ ------------
         1             791020       791020
         2             791020       791020
         3             791020       791020
         4             791020       791020

4 rows selected.

3. 数据文件头检查点

SQL> select CHECKPOINT_CHANGE# from v$datafile_header;

CHECKPOINT_CHANGE#
------------------
            791019
            791019
            791019
            791019

4 rows selected.

世家发现没有?系统一检查查点和数据文件检查点是平等的,但数据文件头检查点是分裂的。

总结:

品味了诸数次,包蕴关闭数据库实行数据库冷备,数据文件头检查点和上述四个检查点的数值总是区别,而且连连比上述检查点的数值少1,疑忌那是个bug,综上说述,此次试验就那样持续了之了,后续有时光的话再行测试。同时,官方文书档案中有一段话:

Because CloneDB databases use the backup files as their backend storage, the backup files must be available to each CloneDB database for it to run.If the backup files become unavailable, then the CloneDB databases return errors.

趣味正是在运作克隆数据库的时候,备份文件必须是可用的,假诺剔除了备份文件或然卸载了NFS文件系统,则克隆数据库将不可用。

很诧异,可惜没有机会举行测试。

即使该试验末了未遂,但频仍做了重重次,中间结果并不像实验步骤那样直观,有以下几点首要注意:

1> 刚开始做测试的时候,写的是/u01 *(rw),后来启用Direct
NFS,创造tablespace做测试时会报以下错误:

SQL>  create tablespace test datafile '/backup/prod/test.dbf' size 2m;
 create tablespace test datafile '/backup/prod/test.dbf' size 2m
*
ERROR at line 1:
ORA-01119: error in creating database file '/backup/prod/test.dbf'
ORA-27086: unable to lock file - already in use
Linux Error: 37: No locks available
Additional information: 10

新兴改为/u01
*(rw,no_root_squash)就从未报该错误,RAC文书档案里引进的是/u01
*(rw,sync,no_wdelay,insecure,insecure_locks,no_root_squash)。

2> 即使利用索罗德MAN备份的话,一定要在备份格局下,即’alter database begin
backup’,借使直接backup as copy database format
‘/backup/prod/%U’,在实施

dbren.sql脚本时,会产出以下错误: 

SQL> @dbren.sql
SQL> declare
  2  begin
  3  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-SYSAUX_FNO-2_08q553gd' , '/u01/app/oracle/oradata/orcl/ora_data_orcl0.dbf');
  4  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-SYSTEM_FNO-1_07q553dp' , '/u01/app/oracle/oradata/orcl/ora_data_orcl1.dbf');
  5  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-UNDOTBS1_FNO-3_09q553hj' , '/u01/app/oracle/oradata/orcl/ora_data_orcl2.dbf');
  6  dbms_dnfs.clonedb_renamefile('/prod/backup/data_D-PROD_I-289579616_TS-USERS_FNO-4_0bq553i5' , '/u01/app/oracle/oradata/orcl/ora_data_orcl3.dbf');
  7  end;
  8  /

PL/SQL procedure successfully completed.

SQL> show errors;
No errors.
SQL> alter database open resetlogs;
alter database open resetlogs
*
ERROR at line 1:
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/ora_data_orcl1.dbf'

3> 要是数据库启用了Direct NFS,在报告警方日志中会有如下消息:Oracle
instance running with ODM: Oracle Direct NFS ODM Library Version 3.0。

     同时,可查看v$dnfs_servers视图。

SQL> select * from v$dnfs_servers;

 ID SVRNAME         DIRNA      MNTPORT    NFSPORT      WTMAX  RTMAX
--- -------------------- ----- ---------- ---------- ---------- ------
  1 node3.being.com     /u01        44046    2049      32768  32768

    注意:并不是运维了Direct
NFS,该视图就会填充,可通过创办测试表空间来证实create tablespace test
datafile ‘/backup/prod/test.dbf’ size
2m,倘使能创建成功,该视图也会被填充的。

参考文书档案:

1. Direct NFS (DNFS) CloneDB in Oracle Database 11g Release 2 (Patchset
11.2.0.2
onward)
Oracle,

2. Setup Oracle Direct NFS
Client

3. Oracle 11g Direct
NFS

4. Cloning a Database with
CloneDB

相关文章