Database query

This probe performs a SQL-query to one of the following databases:

  • MySQL (4.1 - 5.7),

  • MS SQL (Microsoft SQL Server 2005 / 2008 / 2008 R2 / 2012 / 2014),

  • PostgreSQL (9.x),

  • Oracle (9.0 - 11.2),

  • HP Vertica.

Starting with version 5.0 agent supports TLS for PostgreSQL databases. You can find a guide on setting up encryption on the Setup TLS for PostgreSQL in the "Database query" probe page.

Settings example

image
image
Field Description

JDBC URL

Database URL in the JDBC format

Login

DB username.

Password

DB password.

JDBC properties

Properties of JDBC connection in the JSON format.

SQL query

SQL query text.

Only the SELECT command can be used, and query field is limited to 1024 characters.

Period

How often to perform the check (60 seconds by default).

Result

After the check has been done result is displayed in the Data section:

image
image

Field

Description

count(id)

Number of records in the column ID from the table States.

Rows is an additional field in which the array length is indicated.

Total number of rows is displayed when the array value is the result of the probe or the input data.

Command-line utility

Similar execution of this check in the terminal:

mysql -u saymon -p
mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| saymondb           |
+--------------------+
2 rows in set (0.00 sec)


mysql> use saymondb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> show tables
    -> ;
+--------------------+
| Tables_in_saymondb |
+--------------------+
| class_categories   |
| classes            |
| history            |
| migration          |
| obj_prop_types     |
| object_properties  |
| objects            |
| relation_types     |
| relations          |
| state_history      |
| states             |
+--------------------+
11 rows in set (0.00 sec)


mysql> select count(id) from states;
+-----------+
| count(id) |
+-----------+
|         9 |
+-----------+
1 row in set (0.00 sec)

Known problems and errors

Sensor error! Can not issue data manipulation statements with executeQuery().

SQL query is specified incorrectly.

Sensor error! Connection refused (Connection refused)

It is necessary to check the correctness of the specified port number.

By default:

  • MySQL - 3306;

  • PostgreSQL - 5432;

  • MS SQL - 1433;

  • Oracle - 1521;

  • HP Vertica - 5433.

Sensor error! Access denied for user 'say'@'localhost'

It is necessary to check the correctness of the data which indicated in the fields Login and Password.