2013年(350)
分类: Oracle
2013-04-25 13:18:52
某些时候为了快速创建一个新的(DBCA太慢,而且DBCA创建的库没有数据),或者其它原因,你可以希望直接复制现有数据库,但是又不希望新库与原库重名,这时候就就可以通过重建控制文件的方式修改数据库名。
大致步骤如下:
下面演示通过JSSSTR数据库复制出一个JSSBAK,操作如下:
JSSSTR> alter database backup controlfile to trace;
Database altered.执行下列语句,获取当前生成的trace文件路径:
JSSSTR> select c.value || '/' || d.instance_name || '_ora_' ||
2 to_char(a.spid,'fm99999') || '.trc'
3 from v$process a, v$session b, v$parameter c, v$instance d
4 where a.addr = b.paddr
5 and b.audsid = userenv('sessionid')
6 and c.name = 'user_dump_dest';
C.VALUE||'/'||D.INSTANCE_NAME||'_ORA_'||TO_CHAR(A.SPID,'FM99999')||'.TRC'
--------------------------------------------------------------------------------
/data/oracle/admin/jssstr/udump/jssstr_ora_5612.trcJSSSTR> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.过程略,注意文件要复制完整,包括数据文件,归档文件,Online Redo以及tnsnames.ora,listener.ora等等。
注,控制文件不需要复制。
[oracle@yans3 dbs]$ export ORACLE_SID=jssbak
[oracle@yans3 dbs]$ sqlplus "/ as sysdba"
SQL*Plus: Release 10.2.0.3.0 - Production on Wed Mar 25 15:45:05 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to an idle instance.
SQL> set sqlprompt "JSSBAK> "
JSSBAK> create pfile ='/data/oracle/product/10.2/dbs/pfilejssbak.ora' from spfile ='/data/oracle/product/10.2/dbs/spfilejssstr.ora';
File created.主要修改路径参数和等。过程略
JSSBAK> create spfile from pfile='/data/oracle/product/10.2/dbs/pfilejssbak.ora';
File created.
JSSBAK> startup nomount
ORACLE instance started.
Total System Global Area 524288000 bytes
Fixed Size 2073984 bytes
Variable Size 150997632 bytes
Database Buffers 364904448 bytes
Redo Buffers 6311936 bytes找到Set #2. RESETLOGS case,复制其后的语句并做适当修改。
主要将:
CREATE CONTROLFILE REUSE DATABASE "JSS STR " RESETLOGS ARCHIVELOG
改为:
CREATE CONTROLFILE SET DATABASE "JSSBAK" RESETLOGS ARCHIVELOG
其它文件路径按照实际情况修改,另外由于前面文件是冷复制,因此移除RECOVER DATABASE USING BACKUP CONTROLFILE那一句。
JSSBAK> CREATE CONTROLFILE SET DATABASE "JSSBAK" RESETLOGS ARCHIVELOG
2 MAXLOGFILES 16
3 MAXLOGMEMBERS 3
4 MAXDATAFILES 100
5 MAXINSTANCES 8
6 MAXLOGHISTORY 292
7 LOGFILE
8 GROUP 1 '/data/oracle/oradata/jssbak/redo01.log' SIZE 50M,
9 GROUP 2 '/data/oracle/oradata/jssbak/redo02.log' SIZE 50M,
10 GROUP 3 '/data/oracle/oradata/jssbak/redo03.log' SIZE 50M
11 DATAFILE
12 '/data/oracle/oradata/jssbak/system01.dbf',
13 '/data/oracle/oradata/jssbak/undotbs01.dbf',
14 '/data/oracle/oradata/jssbak/sysaux01.dbf',
15 '/data/oracle/oradata/jssbak/users01.dbf',
16 '/data/oracle/oradata/jssbak/strmtbs01.ora',
17 '/data/oracle/oradata/jssbak/webdata01.dbf'
18 CHARACTER SET ZHS16GBK
19 ;
Control file created.
JSSBAK> ALTER DATABASE OPEN RESETLOGS;
Database altered.
JSSBAK> ALTER TABLESPACE TEMP ADD TEMPFILE '/data/oracle/oradata/jssbak/temp01.dbf' REUSE;
Tablespace altered.如果没有报错,则数据库复制并改名成功。