Skip to content

SQL database

On this page
  1. Settings
  2. When is it healthy?
  3. Example
  4. Good to know

The SQL database sensor connects to a database from a private agent and either checks that the connection works or runs a query and compares its result to an expected value. Use it to know that a database accepts connections — and to watch business values that only the database knows: orders created in the last 15 minutes, replication lag, jobs stuck in a table.

In the wizard: Database → SQL database. Requires an Enterprise plan and an Advanced private agent.

Supported databases: PostgreSQL, SQL Server, MySQL, MariaDB and Oracle.

Settings#

Database connection

Setting Description
Secret The connection string, stored as a secret of the sensor's environment. The list shows the secrets of a compatible type.
Timeout Time allowed for the connection and the query.
Check type Connect: only open a connection. Query: also run a query.

Query (when Check type is Query)

Setting Description
SQL query A query returning a single value. It may use variables.
Condition, Value type, Value to check How to compare the result: equal, not equal, more, less, contains, length, regex.

When is it healthy?#

When the connection opens within the timeout and, in query mode, the condition holds for the returned value. The value is recorded and charted.

Checkout — Orders created, a SQL sensor: chart over a week of the query response time and of the measured value, the number of orders, following the daily traffic.
A SQL sensor can watch a business value, here orders created, as well as the database itself.

Example#

Checkout — Orders created (15 min):

SQL
SELECT count(*) FROM orders WHERE created_at > now() - interval '15 minutes'

with the condition More than 0. If checkout silently stops working, the sensor fails even though every page still answers.

Good to know#

  • Use a read-only database account in the connection string: the agent only needs to connect and read.
  • Binding a secret requires the Manager role.
  • The connection string never leaves Onagre except to the agent that runs the check. See Secret security.