在同一台主机上建立用户管理的复制数据库
下面给出一些步骤
1.备份主数据库(rau)的所有数据文件,备份控制文件到跟踪文件。(rau为主数据库)。
[oracle@source ~]$ sqlplus / as sysdba
SQL> select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
rau
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/home/oracle/oradata/rau/system01.dbf
/home/oracle/oradata/rau/undotbs01.dbf
/home/oracle/oradata/rau/sysaux01.dbf
/home/oracle/oradata/rau/users01.dbf
SQL> alter database begin backup;
Database altered.
SQL> host cp /home/oracle/oradata/rau/*.dbf /home/oracle/duplicate_backup/
SQL> host ls -l /home/oracle/duplicate_backup/
total 768876
-rw-r----- 1 oracle oinstall 251666432 May 6 01:00 sysaux01.dbf
-rw-r----- 1 oracle oinstall 503324672 May 6 01:01 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 May 6 01:01 temp01.dbf
-rw-r----- 1 oracle oinstall 26222592 May 6 01:01 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 6 01:01 users01.dbf
SQL> alter database end backup;
Database altered.
SQL> alter system archive log current;
System altered.
SQL> alter database backup controlfile to trace resetlogs;
Database altered.
2.建立复制数据库各种相关文件的OS目录。
[oracle@source ~]$ echo $ORACLE_BASE
/home/oracle
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb/adump
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb/bdump
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb/cdump
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb/ddump
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb/pfile
[oracle@source ~]$ mkdir $ORACLE_BASE/admin/dupdb/udump
[oracle@source ~]$ mkdir $ORACLE_BASE/oradata/dupdb --数据文件目录
[oracle@source ~]$ mkdir $ORACLE_BASE/flash_recovery_area/DUPDB --使用闪回区存放归档日志
3.建立实例服务。当在unix/linux平台需要使用orapwd工具为复制数据库实例建立口令文件;如果为win平台,需要使用oradim 工具建立实例服务。
[oracle@source ~]$ orapwd file=/home/oracle/product/10.2.0/db_1/dbs/orapwdupdb password=oracle
4.访问主数据库(rau)建立参数文件,并适当修改参数文件。
SQL> select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
rau
SQL> create pfile='$ORACLE_BASE/admin/dupdb/pfile/initdupdb.ora' from spfile;
File created.
SQL> host ls -l $ORACLE_BASE/admin/dupdb/pfile
total 4
-rw-r--r-- 1 oracle oinstall 990 May 6 01:26 initdupdb.ora
修改initdupdb.ora文件的这些参数:
dupdb.__db_cache_size=180355072
dupdb.__java_pool_size=4194304
dupdb.__large_pool_size=4194304
dupdb.__shared_pool_size=83886080
dupdb.__streams_pool_size=0
*.audit_file_dest='/home/oracle/admin/dupdb/adump'
*.background_dump_dest='/home/oracle/admin/dupdb/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/home/oracle/oradata/dupdb/control01.ctl','/home/oracle/oradata/dupdb/control02.ctl','/home/oracle/oradata/dupdb/control03.ctl'
*.core_dump_dest='/home/oracle/admin/dupdb/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='dupdb'
*.db_recovery_file_dest='/home/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers=''
*.job_queue_processes=10
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=91226112
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=274726912
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/home/oracle/admin/dupdb/udump'
如果不使用闪回区存放归档日志,log_archive_dest_n也需要修改。
如果参数文件中含有实例名(instance_name)、服务名(service_names),也需要修改。
5.复制主数据库的数据文件备份到复制数据库所在的目录。
[oracle@source ~]$ cp /home/oracle/duplicate_backup/*.dbf /home/oracle/oradata/dupdb/
[oracle@source ~]$ ll /home//oracle/oradata/dupdb/
total 768876
-rw-r----- 1 oracle oinstall 251666432 May 6 01:58 sysaux01.dbf
-rw-r----- 1 oracle oinstall 503324672 May 6 01:59 system01.dbf
-rw-r----- 1 oracle oinstall 20979712 May 6 01:59 temp01.dbf
-rw-r----- 1 oracle oinstall 26222592 May 6 01:59 undotbs01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 6 01:59 users01.dbf
6.启动实例,并建立控制文件。
[oracle@source ~]$ export ORACLE_SID=dupdb
[oracle@source ~]$ sqlplus / as sysdba
SQL> startup nomount pfile='$ORACLE_BASE/admin/dupdb/pfile/initdupdb.ora';
ORACLE instance started.
Total System Global Area 276824064 bytes
Fixed Size 2020160 bytes
Variable Size 92277952 bytes
Database Buffers 180355072 bytes
Redo Buffers 2170880 bytes
SQL> create spfile from pfile;
create spfile from pfile
*
ERROR at line 1:
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file
'/home/oracle/product/10.2.0/db_1/dbs/initdupdb.ora'
SQL> create spfile from pfile='$ORACLE_BASE/admin/dupdb/pfile/initdupdb.ora';
File created.
SQL> CREATE CONTROLFILE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 '/home/oracle/oradata/dupdb/redo01.log' SIZE 50M,
9 GROUP 2 '/home/oracle/oradata/dupdb/redo02.log' SIZE 50M,
10 GROUP 3 '/home/oracle/oradata/dupdb/redo03.log' SIZE 50M
11 DATAFILE
12 '/home/oracle/oradata/dupdb/system01.dbf',
13 '/home/oracle/oradata/dupdb/undotbs01.dbf',
14 '/home/oracle/oradata/dupdb/sysaux01.dbf',
15 '/home/oracle/oradata/dupdb/users01.dbf'
16 CHARACTER SET AL32UTF8
17 ;
Control file created.
7.恢复复制数据库。
[oracle@source 2012_05_06]$ cp o1_mf_1_2_7tbqdyn6_.arc /home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06/
SQL> recover database using backup controlfile until cancel
ORA-00279: change 540666 generated at 05/06/2012 00:56:16 needed for thread 1
ORA-00289: suggestion :
/home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06/o1_mf_1_2_%u_.arc
ORA-00280: change 540666 for thread 1 is in sequence #2
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00279: change 540986 generated at 05/06/2012 01:04:30 needed for thread 1
ORA-00289: suggestion :
/home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06/o1_mf_1_3_%u_.arc
ORA-00280: change 540986 for thread 1 is in sequence #3
ORA-00278: log file
'/home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06/o1_mf_1_2_7tbqdyn6
_.arc' no longer needed for this recovery
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log
'/home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06/o1_mf_1_3_%u_.arc'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> select name from v$archived_log; --已成功应用该归档
NAME
--------------------------------------------------------------------------------
/home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06/o1_mf_1_2_7tbqdyn6_
.arc
可能是由于使用闪回区存放归档日志的原因,使用set logsource ‘/home/oracle/flash_recovery_area/RAU/archivelog/2012_05_06/’ 指定要使用的归档目录、
或使用ALTER DATABASE REGISTER LOGFILE '/home/oracle/flash_recovery_area/RAU/archivelog/2012_05_06/o1_mf_1_2_%u_.arc' 或
ALTER DATABASE REGISTER LOGFILE '/home/oracle/flash_recovery_area/RAU/archivelog/2012_05_06/o1_mf_1_2_7tbqdyn6_.arc';
均不能正常注册归档日志(报错:ORA-00604: error occurred at recursive SQL level)。
最后将需要的归档日志从home/oracle/flash_recovery_area/RAU/archivelog/2012_05_06 复制到home/oracle/flash_recovery_area/DUPDB/archivelog/2012_05_06后,直接运行recover database using backup controlfile until cancel 便能够识别需要的归档日志,然后成功打开数据库。
8.使用resetlogs打开数据库。
SQL> alter database open resetlogs;
Database altered.
SQL> select checkpoint_change#,resetlogs_change# from v$database;
CHECKPOINT_CHANGE# RESETLOGS_CHANGE#
------------------ -----------------
540988 540987
SQL> select checkpoint_change# from v$datafile;
CHECKPOINT_CHANGE#
------------------
540988
540988
540988
540988
SQL> select checkpoint_change#,resetlogs_change# from v$datafile_header;
CHECKPOINT_CHANGE# RESETLOGS_CHANGE#
------------------ -----------------
540988 540987
540988 540987
540988 540987
540988 540987
到此成功将rau数据库复制为dupdb数据库。