oracle 11g 修改資料庫名字和例項名字
分兩個階段描述,第一階段改sid,第二階段改dbname
下面描述詳細步驟
第一階段:改sid
1、登入資料庫檢視先前的sid,總共三步,
[javascript] view plain copy print?
[oracle@localhost ~]$ sqlplus /as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 1 16:51:35 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance
SQL> startup
ORACLE instance started.
Total System Global Area 539848704 bytes
Fixed Size 1337748 bytes
Variable Size 360711788 bytes
Database Buffers 171966464 bytes
Redo Buffers 5832704 bytes
Database mounted.
Database opened.
SQL> select instance from v$thread ;
INSTANCE
--------------------------------------------------------------------------------
orcl
2、關閉資料庫
[sql] view plain copy print?
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
3、編輯/etc/oratab檔案,把所有orcl換成test,大部分情況其實就一條。----這幾步不需要管的。
[sql] view plain copy print?
[oracle@localhost ~]$ vim /etc/oratab
4、更改oracle使用者的 .bash_profile檔案,把orcl改成test
[sql] view plain copy print?
[oracle@localhost ~]$ vim .bash_profile
5、使改好的.bash_profile檔案生效
[sql] view plain copy print?
[oracle@localhost ~]$ . .bash_profile
7、檢視系統環境變數
[sql] view plain copy print?
[oracle@localhost ~]$ env | grep ORACLE
ORACLE_UNQNAME=test
ORACLE_SID=test
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
效果已經生成。
8、進入$ORACLE_HOME/dbs檢視目錄,看那些有orcl,改成test
[sql] view plain copy print?
[oracle@localhost ~]$ cd $ORACLE_HOME/dbs
[oracle@localhost dbs]$ ll
總計 24
-rw-rw---- 1 oracle oinstall 1544 10-01 16:55 hc_orcl.dat
-rw-r--r-- 1 oracle oinstall 2851 2009-05-15 init.ora
-rw-r----- 1 oracle oinstall 24 09-28 20:57 lkORCL
-rw-r----- 1 oracle oinstall 1536 09-29 09:42 orapworcl
drwx------ 2 oracle oinstall 4096 09-28 20:55 peshm_orcl_0
-rw-r----- 1 oracle oinstall 2560 10-01 16:53 spfileorcl.ora
9、更改檔名orcr>> test,ORCL>>test,命令如下:
[sql] view plain copy print?
[oracle@localhost dbs]$ mv hc_orcl.dat hc_test.dat
[oracle@localhost dbs]$ mv orapworcl orapwtest
[oracle@localhost dbs]$ mv lkORCL lkTEST
[oracle@localhost dbs]$ mv peshm_orcl_0/ peshm_test_0/
[oracle@localhost dbs]$ mv spfileorcl.ora spfiletest.ora
10、重行生成密碼檔案,並檢視
[sql] view plain copy print?
[oracle@localhost dbs]$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=sys entries=5 force=y
[oracle@localhost dbs]$ ls -lrt orap*
-rw-r----- 1 oracle oinstall 2048 10-01 17:02 orapwtest
11、登入資料庫,並檢視例項名字,結果表明sid已由orcl變成test了
[sql] view plain copy print?
[oracle@localhost dbs]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 1 17:03:25 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 539848704 bytes
Fixed Size 1337748 bytes
Variable Size 327157356 bytes
Database Buffers 205520896 bytes
Redo Buffers 5832704 bytes
Database mounted.
Database opened.
SQL> select instance from v$thread
2 ;
INSTANCE
--------------------------------------------------------------------------------
test
第二部分:不用退出登入,接著開始第二部分,更改資料庫名dbname
2.1備份控制檔案
[sql] view plain copy print?
SQL> alter database backup controlfile to trace resetlogs;
Database altered.
2.2關閉並退出資料庫
[sql] view plain copy print?
SQL>
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
2.3 orcale 11.2g的控制檔案的備份目錄為
/u01/app/oracle/diag/rdbms/ORCL/test/trace ###告警日誌裡面 ,注意rdbms後面應該是ORCL,因為資料庫名字還沒有改變。
[sql] view plain copy print?
[oracle@localhost trace]$ ls -lrt
總計 80
-rw-r----- 1 oracle oinstall 256 10-01 17:03 test_ora_5286.trm
-rw-r----- 1 oracle oinstall 14393 10-01 17:03 test_ora_5286.trc
-rw-r----- 1 oracle oinstall 68 10-01 17:03 test_mman_5334.trm
-rw-r----- 1 oracle oinstall 852 10-01 17:03 test_mman_5334.trc
-rw-r----- 1 oracle oinstall 61 10-01 17:03 test_cjq0_5437.trm
-rw-r----- 1 oracle oinstall 993 10-01 17:03 test_cjq0_5437.trc
-rw-r----- 1 oracle oinstall 82 10-01 17:04 test_dbrm_5328.trm
-rw-r----- 1 oracle oinstall 1172 10-01 17:04 test_dbrm_5328.trc
-rw-r----- 1 oracle oinstall 90 10-01 17:05 test_vktm_5320.trm
-rw-r----- 1 oracle oinstall 1233 10-01 17:05 test_vktm_5320.trc
-rw-r----- 1 oracle oinstall 72 10-01 17:05 test_vkrm_5439.trm
-rw-r----- 1 oracle oinstall 996 10-01 17:05 test_vkrm_5439.trc
-rw-r----- 1 oracle oinstall 174 10-01 17:05 test_ora_5419.trm
-rw-r----- 1 oracle oinstall 5894 10-01 17:05 test_ora_5419.trc
-rw-r----- 1 oracle oinstall 5969 10-01 17:05 alert_test.log
[oracle@localhost trace]$ vim alert_test.log
[sql] view plain copy print?
可以在 alter_test.log裡找到contolfile的備份trc,<em>sid_</em>ora_nnnn.trc 最新的一個就是。
alter_test.log裡面有這樣一行字樣,告訴你哪個是控制備份檔案
[sql] view plain copy print?
Backup controlfile written to trace file /u01/app/oracle/diag/rdbms/orcl/test/trace/test_ora_5419.trc
2.5複製一份
[sql] view plain copy print?
[oracle@localhost trace]$ cp test_ora_5419.trc test.sql
2.6編輯 test.sql,也就是test_ora_5419.trc的複製品。
1)查詢STARTUP NOMOUNT語句,將這一行上面的所有行都刪除
2)查詢所有以--開始的行,把這些行刪除
3)查詢所有的orcl修改為test,所有的ORCL修改為test ###這個步驟不做也可以,做的目的就是為了符合規矩,實際上控制檔案資料檔案的目錄是可以隨便起的。
4)找到CREATE CONTROLFILE REUSE DATABASE...語句,將其中的REUSE修改為SET
5)找到RECOVER DATABASE USING BACKUP CONTROLFILE語句,將其用雙橫線(--)註釋掉
結果如下:
[sql] view plain copy print?
STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "test" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/test/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/test/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/test/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/test/system01.dbf',
'/u01/app/oracle/oradata/test/sysaux01.dbf',
'/u01/app/oracle/oradata/test/undotbs01.dbf',
'/u01/app/oracle/oradata/test/users01.dbf',
'/u01/app/oracle/oradata/test/example01.dbf'
CHARACTER SET ZHS16GBK
;
--RECOVER DATABASE USING BACKUP CONTROLFILE
ALTER DATABASE OPEN RESETLOGS;
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/test/temp01.dbf'
SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
2.7生成配置檔案
[sql] view plain copy print?
[oracle@localhost trace]$ sqlplus /as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 1 17:12:48 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create pfile from spfile;
File created.
SQL> exit
Disconnected
2.8目錄更改,這裡和oracle 10g不一樣,要注意。
[sql] view plain copy print?
[oracle@localhost ~]$ cd /u01/app/oracle/
[oracle@localhost oracle]$ ls
admin cfgtoollogs checkpoints diag flash_recovery_area oradata product
[oracle@localhost oracle]$ cd flash_recovery_area/
[oracle@localhost flash_recovery_area]$ ls
orcl ORCL
[oracle@localhost flash_recovery_area]$ mv orcl/ test/
[oracle@localhost flash_recovery_area]$ mv ORCL/ test/
[oracle@localhost flash_recovery_area]$ cd ..
[oracle@localhost oracle]$ ls
admin cfgtoollogs checkpoints diag flash_recovery_area oradata product
[oracle@localhost oracle]$ cd oradata/
[oracle@localhost oradata]$ ls
orcl
[oracle@localhost oradata]$ mv orcl/ test/
[oracle@localhost oradata]$ ls
test
[oracle@localhost oradata]$ cd ..
[oracle@localhost oracle]$ ls
admin cfgtoollogs checkpoints diag flash_recovery_area oradata product
[oracle@localhost oracle]$ cd diag/
[oracle@localhost diag]$ ls
rdbms tnslsnr
[oracle@localhost diag]$ cd rdbms/
[oracle@localhost rdbms]$ ls
orcl
[oracle@localhost rdbms]$ mv orcl/ test/
[oracle@localhost rdbms]$ ls
test
[oracle@localhost rdbms]$ cd test
[oracle@localhost test]$ ls
i_1.mif test orcl
[oracle@localhost test]$ cd ..
[oracle@localhost rdbms]$ cd ..
[oracle@localhost diag]$ ls
rdbms tnslsnr
[oracle@localhost diag]$ cd ..
[oracle@localhost oracle]$ cd admin/
[oracle@localhost admin]$ ls
orcl
[oracle@localhost admin]$ cd orcl/
[oracle@localhost orcl]$ ls
adump dpdump pfile
[oracle@localhost orcl]$ cd ..
[oracle@localhost admin]$ mv orcl/ test/
[oracle@localhost admin]$ ls
test
[oracle@localhost admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 1 17:18:02 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL>
2.9刪除的控制檔案。
[sql] view plain copy print?
[oracle@localhost oradata]$ cd test/
[oracle@localhost test]$ ls
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
[oracle@localhost test]$ mv control01.ctl control01.ctl.aaa
[oracle@localhost test]$ ls
control01.ctl.aaa redo01.log redo03.log system01.dbf undotbs01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
[oracle@localhost test]$ cd ..
[oracle@localhost oradata]$ ls
test
[oracle@localhost oradata]$ cd..
bash: cd..: command not found
[oracle@localhost oradata]$ cd ..
[oracle@localhost oracle]$ ls
admin cfgtoollogs checkpoints diag flash_recovery_area oradata product
[oracle@localhost oracle]$ cd flash_recovery_area/
[oracle@localhost flash_recovery_area]$ ls
test test
[oracle@localhost flash_recovery_area]$ cd test/
[oracle@localhost test]$ ls
control02.ctl
[oracle@localhost test]$ mv control02.ctl control02.ctl.aaa
2.10登入oracle生成spfile檔案
[sql] view plain copy print?
[oracle@localhost test]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Oct 1 17:23:34 2011
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile from pfile='?/dbs/inittest.ora';
File created.
2.11呼叫前面步驟修改好的test.sql,目的是生成連結控制檔案等
[sql] view plain copy print?
SQL> @/u01/app/oracle/diag/rdbms/test/test/trace/test.sql
ORACLE instance started.
Total System Global Area 539848704 bytes
Fixed Size 1337748 bytes
Variable Size 327157356 bytes
Database Buffers 205520896 bytes
Redo Buffers 5832704 bytes
Control file created.
Database altered.
Tablespace altered.
2.12檢視結果
[sql] view plain copy print?
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string test
db_unique_name string test
global_names boolean FALSE
instance_name string test
lock_name_space string
log_file_name_convert string
service_names string test.localdomain
SQL> select name from v$database;
NAME
---------
test
SQL>
上表明更改成功。
小結: 針對目錄:$ORACLE_BASE/diag/rdbms/db_name/oracle_sid/trace
當你改掉例項名之後重啟資料庫後,就會在$ORACLE_BASE/diag/rdbms/db_name生成一個新的目錄(名字就是你新起名字的sid) ,當然當你修改了資料庫名字之後,$ORACLE_BASE/diag/rdbms/後面就生成一個和你新起的資料庫名字一樣的目錄。
透過上面的過程我們可以看出來 ,修改已經建立好庫的資料庫名字和sid是相當麻煩的過程,所以儘量不去修改,建立的時候要考慮周到.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-2104248/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 修改資料庫檔名字和路徑資料庫
- 修改+asm的名字!ASM
- 更改ORACLE資料檔名字的方法Oracle
- Oracle例項和Oracle資料庫Oracle資料庫
- Git修改分支的名字Git
- linux修改網路卡名字Linux
- go: 修改應用的名字Go
- 【實驗】修改資料檔名字的三種途徑
- 怎麼修改MAC電腦名字,三步教你修改MAC電腦的名字Mac
- Oracle 11G資料庫單例項安裝Oracle資料庫單例
- 修改oracle例項名(sid)和資料庫名(db_name)Oracle資料庫
- 修改oracle使用者名稱,表空間名字,Oracle
- Linux Ubuntu 修改網路卡名字LinuxUbuntu
- Linux修改網路卡的名字Linux
- oracle 資料庫例項Oracle資料庫
- 重新命名資料夾名字
- oracle 11g 單例項資料庫的安裝Oracle單例資料庫
- 如何修改資料庫例項及資料庫名資料庫
- oracle例項和資料庫的區別Oracle資料庫
- 資料庫和例項資料庫
- oracle資料庫與oracle例項Oracle資料庫
- Oracle例項和Oracle資料庫(Oracle體系結構)Oracle資料庫
- Oracle database的names(名字們)OracleDatabase
- oracle資料庫例項狀態Oracle資料庫
- Oracle12c中配置例項引數和修改容器資料庫(CDB)及可插拔資料庫(PDB)Oracle資料庫
- oracle 修改ORACLE例項Oracle
- oracle資料庫名和例項名的區別Oracle資料庫
- ORACLE 11G 無法連線到資料庫例項故障排除Oracle資料庫
- 名字查詢
- oracle資料庫建立資料庫例項-九五小龐Oracle資料庫
- 程式碼規範----名字(把資訊裝入名字中、選擇不被誤解的名字)
- 建立ASM例項和資料庫ASM資料庫
- linux 批量修改檔名字尾名命令renameLinux
- c++ 獲取資料夾目錄名字C++
- C++標準庫名字和標頭檔案--表C++
- 4 管理資料庫例項和叢集資料庫資料庫
- oracle例項、資料庫及相關資料庫狀態的理解和測試Oracle資料庫
- 多個資料庫是否可以共有一個Oracle 11g RAC例項KG資料庫Oracle