The sql() driver sends messages into an SQL database.
Currently the Microsoft SQL (MSSQL), MySQL, Oracle, PostgreSQL, and SQLite databases
are supported.
The sql() driver has the following required parameters:
| Type: | mssql, mysql, oracle, pgsql, or sqlite3 |
| Default: | n/a |
Description: Specifies the type of the database, i.e., the DBI database driver
to use. Use the mssql option to send logs to
an MSSQL database. See the examples of the databases on the
following sections for details.
| Type: | string |
| Default: | n/a |
Description: Name of the database table to use (can include macros). When using macros, note that some databases limit the length of table names.
| Type: | string list |
| Default: | "date", "facility", "level", "host", "program", "pid", "message" |
Description: Name of the columns storing the data in fieldname
[dbtype] format. The [dbtype]
parameter is optional, and specifies the type of the field. By
default, syslog-ng creates text columns. Note
that not every database engine can index text fields.
| Type: | string list |
| Default: | "${R_YEAR}-${R_MONTH}-${R_DAY} ${R_HOUR}:${R_MIN}:${R_SEC}", "$FACILITY", "$LEVEL", "$HOST", "$PROGRAM", "$PID", "$MSGONLY" |
Description:The parts of the message to store in the fields specified in the
columns parameter.
For the list of available optional parameters, see Section 6.2.4, “sql()”.
Declaration:
sql(database_type host_parameters database_parameters [options]);
![]() |
Warning |
|---|---|
|
The syslog-ng application requires read and write access to the SQL table, otherwise it cannot verify that the destination table exists. Currently the syslog-ng application has default schemas for the different databases and uses these defaults if the database schema (for example columns and column types) is not defined in the configuration file. However, these schemas will be deprecated and specifying the exact database schema will be required in later versions of syslog-ng. |
![]() |
Note |
|---|---|
|
In addition to the standard syslog-ng packages, the
The |
The table and value parameters can
include macros to create tables and columns dynamically (see Section 6.5, “Macros” for details).
![]() |
Warning |
|---|---|
When using macros in table names, note that some databases limit the maximum allowed length of table names. Consult the documentation of the database for details. |
Inserting the records into the database is performed by a separate thread. The syslog-ng application automatically performs the escaping required to insert the messages into the database.
The Oracle sql destination has some special aspects that are important to note.
The hostname of the database server is set in the
tnsnames.ora file, not in the
host parameter of the
sql() destination.
Make sure to set the Oracle-related environment variables properly, so
syslog-ng and the Oracle client will find the file. The following
variables must be set: ORACLE_BASE,
ORACLE_HOME, and
ORACLE_SID. See the documentation of the Oracle
Instant Client for details.
As certain database versions limit the maximum length of table names, macros in the table names should be used with care.
In the current version of syslog-ng PE, the types of database columns
must be explicitly set for the Oracle destination. The column used to
store the text part of the syslog messages should be able to store
messages as long as the longest message permitted by syslog-ng,
therefore it is usually recommended to use the
varchar2 or clob column
type. (The maximum length of the messages can be set using the
log_msg_size() option.) See the following
example for details.
The mssql database driver can access Microsoft SQL
(MSSQL) destinations. This driver has some special aspects that are important to
note.
The date format used by the MSSQL database must be explicitly set in
the /etc/locales.conf file of the syslog-ng server.
See the following example for details.
As certain database versions limit the maximum length of table names, macros in the table names should be used with care.
In the current version of syslog-ng PE, the types of database columns
must be explicitly set for the MSSQL destination. The column used to
store the text part of the syslog messages should be able to store
messages as long as the longest message permitted by syslog-ng. The
varchar column type can store maximum 4096
bytes-long messages. The maximum length of the messages can be set using
the log_msg_size() option. See the following
example for details.
Remote access for SQL users must be explicitly enabled on the Microsoft Windows host running the Microsoft SQL Server. See Section 3.6, “Configuring Microsoft SQL Server to accept logs from syslog-ng” for details.
© 2007-2010 BalaBit IT Security
Please send your comments or documentation bugs to: documentation@balabit.com