oracle-故障-在dg备库使用DB LINK跨库查询时遇到ORA-16000

简介:

在dg备库使用DB LINK跨库查询时遇到ORA-16000: database open for read-only access错误。

执行以下语句报错:
select * from userA.v_view1;

查看对象 v_view1:

PROMPT View v_view1;
--
-- v_view1  (View)
--

CREATE OR REPLACE FORCE VIEW userA.v_view1
(
   TIMESTAMP,
   COMPNAME,
   INNERBATCH,
   VENDER,
   AMOUNT
)
AS
   SELECT ta.timestamp,
          ta.compname,
          tb.innerbatch,
          tb.vender,
          ta.amount
     FROM tab1 ta
          LEFT JOIN tab2@db1 tb ON ta.compid = tb.mrn
    WHERE 1 = 1 --and timestamp >= TO_DATE(TO_CHAR(SYSDATE-1,'YYYYMMDD'),'YYYYMMDD')
             --and timestamp < TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'YYYYMMDD')
           AND ta.actionid IN (300, 301, 302)
   UNION ALL
   SELECT tc.insert_time,
          tc.compname,
          td.innerbatch,
          td.vender,
          tc.amount
     FROM tab3 tc
          LEFT JOIN tab2@db2 td ON tc.compid = td.mrn
    WHERE 1 = 1
--and insert_time >= TO_DATE(TO_CHAR(SYSDATE-1,'YYYYMMDD'),'YYYYMMDD')
--and insert_time < TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'YYYYMMDD')
;


Prompt 将 VIEW v_view1 TO BITEST 的权限授予 BITEST;
GRANT SELECT ON WMS.v_view1 TO BITEST;

分析:

这个视图里使用了两个DB LINK,使用DB LINK查询会创建一个事务,同时使用两个DB LINK就需要创建两个事务,这就需要支持分布式事务,新数据库是ADG的一个备库,并不支持分布式事务,就会上面的错误。

可以通过以下实验来验证。

打开一个会话,先使用dblinkA这个DB LINK查询,,这样第二个DB LINK的查询就会遇到ORA-16000错误。



    SQL> select 1 from dual@dblinkA;

             1
    ----------
             1

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

在第一个DB LINK打开的事务结束后,第二个DB LINK可以创建事务,也就可以使用了。
    SQL> select 1 from dual@dblinkA;

             1
    ----------
             1
    SQL> commit;

    Commit complete.

    SQL> select 1 from dual@dblinkB;

             1
    ----------
             1

    SQL>  
    

如视图或存储过程中使用了两个DBLINK就会报错,如类似如下报表查询想放在ADG上执行以减轻主库的性能压力,就会报错ORA-16000: database open for read-only access:

  CREATE OR REPLACE FORCE VIEW "test"."T_REPORT" (………) AS    select from test.test_REPORT@testzrzk a,mpi.test222@test222 b where a.pid=b.pid and a.TIME>to_char(sysdate-40,'YYYYMMDDHHMISS')
  或
select * from table@dblink1
union
select * from table@dblink2;

参考:

在相关MOS文档中也有对应测试案例,如

Query with multiple dblinks in ADG / read-only database fails with ORA-16000 (Doc ID 2462936.1)

In this Document
Symptoms
Cause
Solution
References

APPLIES TO:
Oracle Database - Enterprise Edition - Version 11.2.0.1 to 12.1.0.2 [Release 11.2 to 12.1]
Information in this document applies to any platform.
SYMPTOMS
In an active Data Guard (ADG) database, execution of a select statement using multiple database links, for example:

select * from table@dblink1
union
select * from table@dblink2
union
select * from table@dblink3;

 

fails with the following error:

ORA-16000: database or pluggable database open for read-only access
*Cause: The database or pluggable database was opened for read-only access.
  Attempts to modify the database using DML or DDL statements generate this error.
*Action: In order to modify the database or pluggable database, it must first be shut down and reopened for read/write access.

CAUSE
This issue is due to a limitation with read-only databases including ADG and is therefore expected behaviour as documented in the following:


11.2 Database Administrator's Guide https://docs.oracle.com/cd/E11882_01/server.112/e25494/toc.htm
Chapter 3 Starting Up and Shutting Down
Section: Opening a Database in Read-Only Mode
Limitations of a Read-only Database

which states:

"When executing on a read-only database, you must commit or roll back any in-progress transaction that involves one database link before you use another database link.
This is true even if you execute a generic SELECT statement on the first database link and the transaction is currently read-only."
 
This issue was also addressed in the following bug closed as 'Not a Bug' for the above reason:

Bug:17630569: ADG STANDBY QUERY WITH MULTIPLE DB LINKS THROWS ORA-16000
 

NOTE:  The following note recommends using "set transaction read only", but this workaround doesn't resolve the ORA-16000 when the select includes multiple dblinks:

Dblink on Physical standby - ORA-16000 (Doc ID 1296288.1)

SOLUTION
Do not use multiple dblinks in a select query in an ADG or read-only database. Consider using a temporary table as an option.
目录
相关文章
|
7月前
|
Oracle 关系型数据库 Linux
【YashanDB 知识库】通过 dblink 查询 Oracle 数据时报 YAS-07301 异常
客户在使用 YashanDB 通过 yasql 查询 Oracle 数据时,遇到 `YAS-07301 external module timeout` 异常,导致 dblink 功能无法正常使用,影响所有 YashanDB 版本。原因是操作系统资源紧张,无法 fork 新子进程。解决方法包括释放内存、停掉不必要的进程或增大进程数上限。分析发现异常源于 system() 函数调用失败,返回 -1,通常是因为 fork() 失败。未来 YashanDB 将优化日志信息以更好地诊断类似问题。
|
6月前
|
Oracle 关系型数据库 数据库
【赵渝强老师】Oracle的闪回版本查询
本文介绍了Oracle数据库的闪回版本查询(Flashback Version Query)功能,通过示例详细讲解了其使用方法。闪回版本查询可获取指定时间区间内行的不同版本,利用`versions between`子句实现。文中包含视频讲解,并通过创建测试表、插入数据及执行查询等步骤,演示如何获取历史版本信息和伪列详情,帮助用户深入了解该功能的实际应用。
119 13
|
5月前
|
SQL Oracle 关系型数据库
【赵渝强老师】Oracle的闪回事务查询
Oracle数据库的闪回事务查询(Flashback Transaction Query)是闪回版本查询的扩充,可用于审计或撤销已提交的事务。通过`flashback_transaction_query`视图,可生成还原特定事务的SQL语句。本文介绍了其基本概念,并通过实战演示如何使用该功能:从授权、开启UNDO数据增强,到创建测试表和事务,最后利用闪回查询撤销已提交的事务,验证数据恢复效果。附带视频讲解,帮助深入理解。
131 3
|
6月前
|
Oracle 关系型数据库 Linux
【YashanDB知识库】通过dblink查询Oracle数据时报YAS-07301异常
【YashanDB知识库】通过dblink查询Oracle数据时报YAS-07301异常
|
6月前
|
SQL Oracle 关系型数据库
【YashanDB知识库】yashandb执行包含带oracle dblink表的sql时性能差
【YashanDB知识库】yashandb执行包含带oracle dblink表的sql时性能差
|
6月前
|
Oracle 关系型数据库 MySQL
【YashanDB知识库】oracle dblink varchar类型查询报错记录
这篇文章主要介绍了 Oracle DBLINK 查询崖山 DB 报错的相关内容,包括 ODBC 安装配置、数据源配置、dblink 环境配置、问题原因分析及规避方法。问题原因是 dblink 连接其他数据库时 varchar 类型转换导致的,还介绍了 long 类型限制、char 等类型区别,规避方法是修改参数 MAX_STRING_SIZE 支持 32K。
|
7月前
|
Oracle 关系型数据库 Linux
【YashanDB 知识库】通过 dblink 查询 Oracle 数据时报 YAS-07301 异常
某客户在使用 YashanDB 通过 yasql 查询 Oracle 数据时,遇到 `YAS-07301 external module timeout` 异常,导致 dblink 功能无法正常使用,影响所有版本。问题源于操作系统资源紧张,无法 fork 新子进程。解决方法包括释放内存、停掉不必要的进程或增大进程数上限。分析发现异常原因为系统调用 fork() 失败。经验总结:优化日志记录,提供更多异常信息。
|
8月前
|
Oracle 关系型数据库 数据库
【YashanDB知识库】oracle dblink varchar类型查询报错记录
在使用Oracle DBLink查询VARCHAR类型数据时,可能会遇到多种报错。通过了解常见错误原因,采取合适的解决方法,可以有效避免和处理这些错误。希望本文提供的分析和示例能帮助你在实际工作中更好地处理DBLink查询问题。
215 10
|
8月前
|
SQL Oracle 关系型数据库
如何在 Oracle 中配置和使用 SQL Profiles 来优化查询性能?
在 Oracle 数据库中,SQL Profiles 是优化查询性能的工具,通过提供额外统计信息帮助生成更有效的执行计划。配置和使用步骤包括:1. 启用自动 SQL 调优;2. 手动创建 SQL Profile,涉及收集、执行调优任务、查看报告及应用建议;3. 验证效果;4. 使用 `DBA_SQL_PROFILES` 视图管理 Profile。
|
9月前
|
存储 Oracle 关系型数据库
数据库数据恢复—ORACLE常见故障的数据恢复方案
Oracle数据库常见故障表现: 1、ORACLE数据库无法启动或无法正常工作。 2、ORACLE ASM存储破坏。 3、ORACLE数据文件丢失。 4、ORACLE数据文件部分损坏。 5、ORACLE DUMP文件损坏。
388 11