標籤:oracle ora 2069
今天開發給發郵件過來說一個預存程序想通過dblink往目標庫insert資料,但報錯ORA-02069: global_names parameter must be set to TRUE for this operation,想讓我根據錯誤提示在資料庫上修改global_names參數修改為True。
先來看看官方文檔是如何介紹這個參數的:
GLOBAL_NAMES specifies whether a database link is required to have the same name as the database to which it connects.
If the value of GLOBAL_NAMES is false, then no check is performed. If you use or plan to use distributed processing, then Oracle recommends that you set this parameter to true to ensure the use of consistent naming conventions for databases and links in a networked environment.
從下面的查詢可以看出global_names參數可以線上進行修改的
[email protected]>col name for a30[email protected]>select name,ISSES_MODIFIABLE,ISSYS_MODIFIABLE from v$parameter where name=‘global_names‘;NAME ISSES_MODIFIABL ISSYS_MODIFIABLE------------------------------ --------------- ---------------------------global_names TRUE IMMEDIATE
看完了這個參數,再來看看開發的預存程序代碼,其中insert語句中是用到了一個序列,所以導致了這個報錯。先在測試資料庫上建立了一個簡單的預存程序來類比現再這個問題
建立一個dblink
[email protected]>create database link link_orcl connect to zx identified by "zx" using ‘orcl‘;Database link created.[email protected]>select * from [email protected]_orcl;DUM---X
先建立一個不帶序列的遠程insert的預存程序
[email protected]>create or replace procedure pro_a as 2 begin 3 insert into [email protected]_orcl (c1) values(‘a‘); 4 commit; 5 end; 6 /Procedure created.
執行這個預存程序,觀察結果,資料可以正常插入
[email protected]>select * from [email protected]_orcl;no rows selected[email protected]>exec pro_a;PL/SQL procedure successfully completed.[email protected]>select c1 from [email protected]_orcl;C1---a
建立一個序列,並修改上面的預存程序
[email protected]>create sequence seq_a;Sequence created.[email protected]>create or replace procedure pro_a as 2 begin 3 insert into [email protected]_orcl (c1,n1) values(‘a‘,seq_a.nextval); 4 commit; 5 end; 6 / Procedure created.
執行修改後的預存程序,重現上面的錯誤ORA-02069
[email protected]>exec pro_a;BEGIN pro_a; END;*ERROR at line 1:ORA-02069: global_names parameter must be set to TRUE for this operationORA-06512: at "ZX.PRO_A", line 3ORA-06512: at line 1
先在session層面修改global_names參數,再次執行預存程序,又出現了新的錯誤:說兩端的資料庫名不一致。
[email protected]>alter session set global_names = true;Session altered.[email protected]>exec pro_a;BEGIN pro_a; END;*ERROR at line 1:ORA-02085: database link LINK_ORCL connects to ORCLORA-06512: at "ZX.PRO_A", line 3ORA-06512: at line 1[email protected]>!oerr ora 208502085, 00000, "database link %s connects to %s"// *Cause: a database link connected to a database with a different name.// The connection is rejected.// *Action: create a database link with the same name as the database it// connects to, or set global_names=false.
那現在問題來了,實際生產中源端和目標端的資料庫名肯定是不一致的,所以修改這個參數並不能解決這個問題。
只能想其他的辦法來繞過這個錯誤,這裡給開發提了兩個建議:
1、把預存程序部署到目標端來避免遠程insert中調用sequence
2、在源端預存程序中引入暫存資料表,先把資料插入暫存資料表,再從暫存資料表插入到遠端表。
在MOS上搜到了一個相關文檔(ORA-02069 DURING REMOTE INSERT OF A LOCAL SEQUENCE (文檔 ID 1047673.6))跟我們的問題描述一致。
官方文檔:http://docs.oracle.com/cd/E11882_01/server.112/e40402/initparams098.htm#REFRN10065
本文出自 “DBA Fighting!” 部落格,請務必保留此出處http://hbxztc.blog.51cto.com/1587495/1907253
Oracle預存程序報錯ORA-02069: global_names parameter must be set to TRUE for this operation