---
title: "Interacting with the database"
url: "https://axoflow.com/docs/axosyslog-core/4.28/chapter-destinations/configuring-destinations-sql/sql-interactions-syslog-ng/"
last_modified: "2023-06-27T21:05:00+02:00"
---

> For the complete documentation index, see [llms.txt](https://axoflow.com/docs/axosyslog-core/4.28/llms.txt).

# Interacting with the database

## SQL operations

*Create table:*

- If the given table does not exist, AxoSyslog tries to create it with the given column types.
- The AxoSyslog application automatically creates the required tables and columns, if the user account used to connect to the database has the required privileges.
- If AxoSyslog cannot create or alter a table, it tries to do it again when it reaches the next `time-reopen()`.

*Alter table:*

- If the table structure is different from given structure in an existing table, AxoSyslog tries to add columns in this table but never will delete or modify an existing column.
- If AxoSyslog cannot create or alter a table, it tries to do it again when reach the next `time-reopen()`.
- The AxoSyslog application requires read and write access to the SQL table, otherwise it cannot verify that the destination table exists.

*Insert table:*

- Insert new records in a table.
- Inserting the records into the database is performed by a separate thread.
- The AxoSyslog application automatically performs the escaping required to insert the messages into the database.
- If insert returns with error, AxoSyslog tries to insert the message +two times by default, then drops it. Retrying time is the value of `time-reopen()`.

## Encoding

The AxoSyslog application uses UTF-8 by default when writes logs into database.

## Start/stop and reload

*Start:*

- The AxoSyslog application will connect to database automatically after starting regardless existing incoming messages.

*Stop:*

- The AxoSyslog application will close the connection to database before shutting down.

*Possibility of losing logs:*

- The AxoSyslog application cannot lose logs during shutting down if disk buffer was given and it is not full yet.
- The AxoSyslog application cannot lose logs during shutting down if disk buffer was not given.

*Reload:*

- The AxoSyslog application will close the connection to database if it received SIGHUP signal (reload).
- It will reconnect to the database when it tries to send a new message to this database again.

## Macros:

The value of ${SEQNUM} macro will be overridden by sql driver regardless of local or relayed incoming message.

It will be grown continuously.

---

[MySQL-specific interaction methods](https://axoflow.com/docs/axosyslog-core/4.28/chapter-destinations/configuring-destinations-sql/sql-interactions-syslog-ng/mysql-specific-interaction-methods/index.md)

[MsSQL-specific interaction methods](https://axoflow.com/docs/axosyslog-core/4.28/chapter-destinations/configuring-destinations-sql/sql-interactions-syslog-ng/mssql-specific-interaction-methods/index.md)

Last modified June 27, 2023: [Moves content/docs to content/ to shorten output url (a5fcf1ed)](https://github.com/axoflow/axosyslog-core-docs/commit/a5fcf1ed4956f586bc12af2b775e10aa75c1e630)
