在Linux中通過本地複製的方式建立多一個Oracle資料庫

lygle發表於2013-04-18
 在 Oracle 的世界裡,一個例項只能開啟一個資料庫,如果我想在本機中同時執行兩個資料庫,那就要開啟兩個例項了,而不同的例項的標識就是SID。

關閉現有資料庫,設定好一個新的 SID 後,通過複製引數檔案為 spfile.ora 作為新例項的引數檔案,將控制檔案、資料檔案和重做日誌複製一份到相應的目錄,此時新的資料庫就有一個雛形了;將資料庫啟動 nomout 階段修改spfile中的新資料庫的 controlfile 的位置就可以將資料庫啟動到 mount 階段,在 mount 階段將資料檔案和重做日誌的檔案修改到新路徑後就可以開啟資料庫了。

整個過程都很順利,但是此時再試圖開啟原來的資料庫就會報錯了:

 
ORA-01102: cannot mount database in EXCLUSIVE mode

而 alert 檔案中出現如下資訊:

1
2
3
4
5
6
7
8
9
10
11
Sat Oct 9 11:14:18 2010
ALTER DATABASE MOUNT
Sat Oct 9 11:14:18 2010
sculkget: failed to lock /u01/app/oracle/dbs/lkORA8I exclusive
sculkget: lock held by PID: 11621
Sat Oct 9 11:14:18 2010
ORA-09968: Message 9968 not found; No message file for product=RDBMS, facility=ORA
Linux-x86_64 Error: 11: Resource temporarily unavailable
Additional information: 11621
Sat Oct 9 11:14:18 2010
ORA-1102 signalled during: ALTER DATABASE MOUNT...

舊的資料庫的 SID 和 DB_NAME 均是 ORA8I,failed to lock /u01/app/oracle/dbs/lkORA8I exclusive 應該就是問題所在了,在引數檔案中的db_name好改,但是db_name還存在於控制檔案和資料檔案中,這些檔案怎麼改呢? 這個就要藉助nid程式了。

首先將新資料庫啟動到 mount 階段,假設新的資料庫的例項是oratmp,資料庫名也是oratmp。



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
[oracle@l004020 ~]$ export $ORACLE_SID=oratmp
[oracle@l004020 ~]$ nid target=sys/sys_password dbname=oratmp
DBNEWID: Release 10.2.0.2.0 - Production on Sat Oct 9 11:37:47 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to database ORA8I (DBID=152116074)
Connected to server version 10.2.0
Control Files in database:
/u02/oradata/oratmp/control01.ctl
/u02/oradata/oratmp/control02.ctl
/u02/oradata/oratmp/control03.ctl
Change database ID and database name ORA8I to ORATMP? (Y/[N]) => y
Proceeding with operation
Changing database ID from 152116074 to 3320092043
Changing database name from ORA8I to ORATMP
Control File /u02/oradata/oratmp/control01.ctl - modified
Control File /u02/oradata/oratmp/control02.ctl - modified
Control File /u02/oradata/oratmp/control03.ctl - modified
Datafile /u02/oradata/oratmp/system01.dbf - dbid changed, wrote new name
Datafile /u02/oradata/oratmp/undotbs01.dbf - dbid changed, wrote new name
Datafile /u02/oradata/oratmp/sysaux01.dbf - dbid changed, wrote new name
Datafile /u02/oradata/oratmp/users01.dbf - dbid changed, wrote new name
Datafile /u02/oradata/ora8i/temp01.dbf - dbid changed, wrote new name
Control File /u02/oradata/oratmp/control01.ctl - dbid changed, wrote new name
Control File /u02/oradata/oratmp/control02.ctl - dbid changed, wrote new name
Control File /u02/oradata/oratmp/control03.ctl - dbid changed, wrote new name
Instance shut down
Database name changed to ORATMP.
Modify parameter file and generate a new password file before restarting.
Database ID for database ORATMP changed to 3320092043.
All previous backups and archived redo logs for this database are unusable.
Database has been shutdown, open database with RESETLOGS option.
Succesfully changed database name and ID.
DBNEWID - Completed succesfully.
[oracle@l004020 ~]$ sqlplus / as sysdba
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount ;
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 2069648 bytes
Variable Size 104860528 bytes
Database Buffers 50331648 bytes
Redo Buffers 10510336 bytes
ORA-01103: database name 'ORATMP' in control file is not 'ORA8I'
SQL> alter system set db_name='oratmp' scope=spfile;
System altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount ;
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 2069648 bytes
Variable Size 104860528 bytes
Database Buffers 50331648 bytes
Redo Buffers 10510336 bytes
Database mounted.
SQL> alter database open ;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs ;
Database altered.
#再看看hc檔案。
[oracle@l004020 dbs]$ ls -lth hc*
-rw-rw---- 1 oracle dba 1.6K 10-09 11:49 hc_oratmp.dat
-rw-rw---- 1 oracle dba 1.6K 10-09 11:34 hc_ora8i.dat

簡單來說就是如下幾步:

1。startup mount ;

2。nid target=sys/sys_password dbname=oratmp

3。alter system set db_name= ;

4。shutdown

5。startup mount ;

6。alter database open resetlogs。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28673746/viewspace-758731/,如需轉載,請註明出處,否則將追究法律責任。

相關文章