# 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](../../../docs/axosyslog-core/chapter-destinations/configuring-destinations-sql/sql-interactions-syslog-ng/mysql-specific-interaction-methods/index.md)

[MsSQL-specific interaction methods](../../../docs/axosyslog-core/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 (a5fcf1e)](<https://github.com/axoflow/axosyslog-core-docs/commit/a5fcf1ed4956f586bc12af2b775e10aa75c1e630>)