Oracle資料庫的global_name
Oracle資料庫的global_name,在Database Link與GLOBAL_NAMES參數一文中提到了,設定global_names初始化參數為true後,本地的資料庫連結名稱必須與遠端資料庫的global_name相同,才能正常使用資料庫連結。那麼怎麼查詢資料庫的global_name呢。
SQL> col global_name for a30
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB
那麼怎麼樣修改global_name。
ALTER DATABASE
RENAME GLOBAL_NAME TO NEW_NAME;
注意不要直接用update global_name set global_name=”將global_name設定為空白,否則資料庫不能啟動,會報ORA-00600[18061] 或 ORA-00600[18062]這樣的錯誤。 只有用備份進行恢複後才能開啟。(參見metalink note 743676.1)。
那麼global_name到底是個什麼對象呢。
SQL> select owner,object_name,object_type from dba_objects where object_name=’GLOBAL_NAME’;
OWNER OBJECT_NAME OBJECT_TYPE
---------- -------------------- --------------------
SYS GLOBAL_NAME VIEW
PUBLIC GLOBAL_NAME SYNONYM
SQL> select text from dba_views where view_name=’GLOBAL_NAME’;
TEXT
----------------------------------------------------------------
select value$ from sys.props$ where name = ‘GLOBAL_DB_NAME’
可以看到global_name實際上是一個視圖,來源於sys.props$表,而這個表是非常重要的一個關於資料庫屬性的表,不要隨意更改此表的內容,否則將引起無可預料的、無法挽回的損失。
在用alert database rename global_name時,如果設定了global_name類似於”dmdb.com”這樣的名稱,則以後更改名稱,則沒有常規的辦法去掉”.”分隔字元了。
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB
SQL> alter database rename global_name to dmdb.com;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB.COM
SQL> alter database rename global_name to dmdb.cn;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB.CN
SQL> alter database rename global_name to dmdb;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB.CN
SQL> alter database rename global_name to dm;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DM.CN
SQL> alter database rename global_name to dm.com.cn;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DM.COM.CN
SQL> alter database rename global_name to dmdb;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB.COM.CN
SQL> alter database rename global_name to dmdb.net;
Database altered.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB.NET
要去掉點分隔字元,只有用update:
SQL> update global_name set global_name=’DMDB’;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from global_name;
GLOBAL_NAME
------------------------------
DMDB
鄭重提示:除非萬不得已,不要去更新global_name視圖,即時更新,也不要去更新global_name的基表props$,更不要將global_name更新為空白。 #資料庫