oracle multiple database link read only access error

时间:2015-09-14 15:25:44

标签: database oracle dblink

The query is like this

select 1 from dual@link1
union 
select 1 from dual@link2

then i got the read only access error.

I have users in all those 3 databases and they are all read only users, so when i do the query "select 1 from dual@link1" then i got read only error, then i tried to change the query as

set transaction read only;
select 1 from dual@link1;

then it's solved.

then i tried the query as below:

select 1 from dual@link1
union 
select 1 from dual@link2

it error again, i am not sure why 1 link works but 2 links won't work.

any one knows?

1 个答案:

答案 0 :(得分:0)

将数据库置于只读模式并涉及多个dblink是一个非常令人惊讶的限制。

当您从第一个dblink读取时,您应关闭当前事务(!),然后才能从第二个dblink读取。这显然会阻止您使用从两个dblinks连接表的SELECT。

记录在案,但很难找到。在Starting Up and Shutting Down中,您可以看到:

  

在只读数据库上执行时,必须在使用其他数据库链接之前提交或回滚涉及一个数据库链接的任何正在进行的事务。即使您在第一个数据库链接上执行通用SELECT语句并且该事务当前是只读的,也是如此。

重申这个概念,如果你有权访问metalink,那么有一个oracle注释响应客户,它显示了一个例子(Document 1296288.1)澄清了限制

SQL> select * from emp@link_emp_chicago;
select * from emp@link_emp_chicago
*
ERROR at line 1:
ORA-16000: database open for read-only access
Solution

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE
---------- ----------------
READ ONLY PHYSICAL STANDBY

SQL> select owner,db_link from all_db_links;

OWNER
------------------------------
DB_LINK

PUBLIC
LINK_EMP_CHICAGO

SQL> select * from emp@link_emp_chicago;
select * from emp@link_emp_chicago
*
ERROR at line 1:
ORA-16000: database open for read-only access

SQL> set transaction read only;


Transaction set.

SQL> select * from emp@link_emp_chicago;

EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7369 SMITH CLERK 7902 17-DEC-80 800 20

7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30

7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30

只是推测,原因可能与words of Tom Kyte

中的事实有关
  

分发的东西开始交易"以防万一"。