怎样行使Direct NFS克隆数据库

CloneDB是Oracle 11.2.0.3出产的同一件新特性,它利用的了11g新引入的Direct
NFS。它直接采用对象数据库的备份,无需以备份COPY到克隆环境下,使得一个备份可以仿造多个例外用途的数据库。它同时用了copy-on-write技术,使得备份中只有吃改动了底block才见面让运用到克隆数据库中,极大的节了克隆数据库的空间,并升级了数据库克隆的快。

下面对该项特性开展了测试,共涉及三台服务器,采用的咸是32各类RHEL
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

后来察觉实际上无此必要,node1中/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

七、克隆数据库

ORACLE官方文档中提供了少于栽方式,一栽是使用oracle自身提供的剧本,一个凡手动创建。

当此间,我们摘脚本方式,通过脚本执行进程遭到之出口,对比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_DIR指的是备份所在的目录,CLONE_FILE_CREATE_DEST指的是数据文件、日志文件、控制文件所在的目,CLONEDB_NAME指定数量库名

推行数据库提供的perl脚本,关于下论所于的目录及其实施之不二法门,我们来看望官方的认证:

图片 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> 如果用RMAN备份的话,一定要于备份模式下,即’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)

2. Setup Oracle Direct NFS
Client

3. Oracle 11g Direct
NFS

4. Cloning a Database with
CloneDB

相关文章