Get started

InsightsBetter with OwlDB

The standby database: can it take AI queries off production?

AI queries go to the standby, transactions stay on the primary

Ask for "sales by region last month," and the AI doesn't pull the answer right away. It checks table structures, confirms a few values and looks at the execution plan before it sends the main query. One question means several queries, so the AI looks at the database more often than people do. When a database is first connected, it also studies the database in advance by reading statistics and sample values for each table (“The AI's SQL runs fine. Why is the revenue number wrong?”). If all of these queries go to the primary node that handles orders and payments, the business screens your staff use carry that load too.

With OwlDB, OwlDB decides which node runs the AI's queries. If you have a standby node (the backup server kept for failover), it sends the queries that read data there, and the primary stays focused on people's transactions.

AI queries on the standby node, transactions on the primary
Figure 1. AI queries on the standby node, transactions on the primary

OwlAI alone can read from a replica

You can reduce the load on production with OwlAI alone. When an administrator registers the connection, they enter the address of a read-only replica instead of the production database (“Put AI on the production database, and security asks three questions”). That choice, however, is tied to the setup at registration time. If a failover promotes the replica to primary, or the replica stops or falls far behind, someone has to update the connection details. A single connection can't tell whether its node is currently the primary or how far replication has lagged.

OwlDB picks the node at query time

OwlDB already knows each node's role and replication lag. So OwlAI doesn't name a node when it sends a query; it names only the database to run on. OwlDB picks the right node based on what the query does and the state of each node at that moment, runs the query, and returns the result along with which node ran it and why. After a failover, nothing needs to change on the OwlAI side.

If no readable standby is available for the moment, or replication lag exceeds the threshold, OwlDB does not run the query and reports the reason instead. OwlAI retries shortly afterward.

The record shows which node served each query

Letting OwlDB pick the node doesn't mean losing track of where the data came from. Every time SQL runs, OwlAI writes the node that ran it, and why that node was chosen, into its execution record. If someone later asks which server a given answer's data came from on a given day, the record answers it right away. If queries often went to the primary even though a standby was available, the same record shows why.

Schema analysis can run during business hours

Schema analysis, which runs when a database is first connected, sends one query after another for every table. With hundreds of tables, that adds up to thousands of catalog, statistics and sample queries. For databases connected through OwlDB, these queries also go through OwlDB. Queries that read data, such as sample values, run on the standby, while information each server keeps on its own, such as the record of SQL the customer actually ran, is read from the primary. Each server records only its own activity there, so reading it on the standby may not show what actually ran on the primary. Because the queries that read data stay off the primary, you can start the analysis during business hours.

What to check before adoption

  • Whether your production database has a standby node
  • Whether the work the AI answers can read from a standby (whether you can accept data that trails production by the replication lag)
  • When to run schema analysis