You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过JDBC驱动实现Oracle Data Guard主备库的应用故障切换?

Using Oracle JDBC Driver for Data Guard Failover (Non-RAC, No GSLB)

Great question—yes, you absolutely can use the Oracle JDBC driver to handle failover to your Data Guard standby (non-RAC) without needing a GSLB. Let’s break down how to make this work, along with key configurations and prerequisites:

  • Leverage the Oracle Thin Driver’s Built-in Failover Capabilities
    The Oracle JDBC Thin driver natively supports both connect-time failover (for new connections) and Transparent Application Failover (TAF) (for maintaining existing connections during a failure). These features are designed to work with Data Guard setups, so you don’t need external load balancers.

  • Configure the JDBC Connection String Correctly
    Your connection string needs to include both primary and standby database endpoints, with parameters that prioritize the primary and enable failover when it’s unavailable. Here’s a working example:

    jdbc:oracle:thin:@(DESCRIPTION_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)
      (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=primary-db-host)(PORT=1521))
        (CONNECT_DATA=(SERVICE_NAME=your-primary-service)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=standby-db-host)(PORT=1521))
        (CONNECT_DATA=(SERVICE_NAME=your-standby-service))))
    

    Let’s unpack the critical parameters:

    • FAILOVER=ON: Tells the driver to try the next endpoint in the list if the current one is unreachable.
    • LOAD_BALANCE=OFF: Ensures the driver always attempts to connect to the primary first (you only want to fall back to standby when the primary is down).
    • SERVICE_NAME: Use a service that’s configured to exist on both primary and standby. For Data Guard, you can set up a switchover-aware service that automatically registers on the new primary after a failover.
  • Enable TAF for Seamless Existing Connection Failover
    If you want active application connections to keep working without manual restart after a failover, add TAF settings to your connection string. Modify the CONNECT_DATA sections like this:

    (CONNECT_DATA=(SERVICE_NAME=your-service)
      (FAILOVER_MODE=(TYPE=SELECT)(METHOD=BASIC)))
    
    • TYPE=SELECT: Allows ongoing SELECT queries to resume on the standby after failover (note: DML operations will need to be retried manually, as TAF doesn’t handle transactional failures).
    • METHOD=BASIC: Establishes a new connection to the standby as soon as a failure is detected.
  • Check Data Guard Prerequisites

    • Ensure your standby database is in a state where applications can connect: either read-only (for standard Data Guard) or Active Data Guard (if you need read/write access after failover).
    • Verify that the service names in your JDBC string are configured to start automatically on the standby. You can use Oracle Restart (srvctl add service) or manual registration via ALTER SYSTEM REGISTER to set this up.
  • Test the Failover Flow
    Don’t skip this step—validate the setup by:

    1. Gracefully shutting down the primary database.
    2. Confirming new application connections automatically route to the standby.
    3. For TAF-enabled connections, running a long-running SELECT query and triggering a failover to ensure it resumes without errors.

内容的提问来源于stack exchange,提问作者NCSU44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:19:56