Linux下修改Oracle資料庫的sid和dbname

來源:互聯網
上載者:User

有時我們需要修改資料庫的sid和dbname,除了使用rman進行備份恢複之外,也可以通過手工方式修改,主要由兩個主要過程完成:
1、修改執行個體名(SID)
2、修改資料庫名(dbname)

下面示範將資料庫sid和dbname由orcl修改為cnhtm的過程:

1、修改執行個體名(sid)

1.1、檢查原來的資料庫執行個體名(sid)

Oracle@oracle[/home/oracle]> echo $ORACLE_SID
orcl
oracle@oracle[/home/oracle]> sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Dec 20 11:14:49 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
sys@ORCL> select instance from v$thread;
INSTANCE
--------------------------------------------------------------------------------
orcl

1.2、關閉資料庫

注意不能用shutdown abort,只能是shutdown immediate或shutdown normal

sys@ORCL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
sys@ORCL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

1.3、修改oracle使用者的ORACLE_SID環境變數,如由orcl修改為cnhtm

oracle@oracle[/home/oracle]> cat ~/.bash_profile|grep -i sid
ORACLE_SID=cnhtm
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

1.4、修改/etc/oratab檔案,將sid名由舊的修改為新的,如從orcl修改為cnhtm

oracle@oracle[/home/oracle]> cat /etc/oratab
......
cnhtm:/oracle/app/10.1:Y
+ASM:/oracle/app/10.1:Y

1.5、進入到$ORACLE_HOME/dbs目錄

將所有檔案名稱中包含原來的sid的修改為對應的新sid的
如我對如下檔案修改為其後對應的檔案

hc_orcl.dat->hc_cnhtm.dat
lkORCL->lkCNHTM
orapworcl->orapwcnhtm
snapcf_orcl.f->snapcf_cnhtm.f
spfileorcl.ora->spfilecnhtm.ora

1.6、使新修改的ORACLE_SID環境變數生效

oracle@oracle[/oracle/app/10.1/dbs]> . ~/.bash_profile
oracle@oracle[/oracle/app/10.1/dbs]> echo $ORACLE_SID
cnhtm

1.7、重建口令檔案

因為口令檔案改名後不能在新執行個體中使用,所以重建

oracle@oracle[/oracle/app/10.1/dbs]> orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=5 force=y
oracle@oracle[/oracle/app/10.1/dbs]> ls -lrt orapw*
-rw-r----- 1 oracle oinstall 2048 Dec 20 11:27 orapwcnhtm

1.8、啟動資料庫

oracle@oracle[/oracle/app/10.1/dbs]> sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Dec 20 11:29:53 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
idle> startup
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218292 bytes
Variable Size 62916876 bytes
Database Buffers 96468992 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.

1.9、檢查資料庫執行個體名

通過如下語句檢查資料庫執行個體名,發現執行個體名已經由orcl變成cnhtm

idle> select instance from v$thread;
INSTANCE
--------------------------------------------------------------------------------
cnhtm

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.