Back to Dnsserver

Query Logs SQLite App

Apps/QueryLogsSqliteApp/README.md

15.1.03.6 KB
Original Source

Query Logs SQLite App

A DNS App for Technitium DNS Server that logs DNS queries to a SQLite database.

Overview

  • Async logging – writes log entries through a bounded queue
  • Cleanup support – prunes old records by age/count
  • Optional in-memory mode – can use an in-memory database
  • Vacuum support – can vacuum after cleanup when enabled

Integration / extension points

  • Implements: IDnsApplication, IDnsQueryLogger, IDnsQueryLogs
  • Runs as a DNS query logger with asynchronous persistence.

Database

The database table stores values for some fields in numeric format. The fields and the values are described as below.

Protocol Field

ProtocolValueDescription
0UDPThe standard DNS over UDP protocol
1TCPThe standard DNS over TCP protocol
2TLSDNS-over-TLS RFC 7858
3HTTPSDNS-over-HTTPS RFC 8484
5QUICDNS-over-QUIC RFC 9250
253UdpProxyPROXY Protocol over UDP
254TcpProxyPROXY Protocol over TCP

Response Type Field

Response TypeValueDescription
1AuthoritativeResponse generated by the DNS server itself
2RecursiveResponse received from a recursive query to upstream
3CachedResponse generated by DNS server's cache
4BlockedResponse generated by DNS server to block a request
5UpstreamBlockedResponse received from an upstream blocking a request
6UpstreamBlockedCachedResponse generated by DNS server's cache containing blocked response from upstream
7DroppedA null response generated by the DNS server indicating that the request was dropped

Configuration

dnsApp.config contains these keys:

PropertyTypeDefaultDescription
enableLoggingbooleantrueEnables or disables logging.
maxQueueSizenumber200000Size of the bounded log queue.
maxLogDaysnumber0Maximum age of retained logs (days). 0 disables age-based cleanup.
maxLogRecordsnumber0Maximum number of retained log records. 0 disables count-based cleanup.
enableVacuumbooleanfalseRuns VACUUM after cleanup when records were deleted.
useInMemoryDbbooleanfalseUses an in-memory SQLite database.
sqliteDbPathstringquerylogs.dbPath to the SQLite database file.
connectionStringstringData Source='{sqliteDbPath}'; Cache=Shared;SQLite connection string template.

The example below matches the shipped dnsApp.config values, which enable 7-day and 10,000-record cleanup by default in the distributed package.

Example

json
{
  "enableLogging": true,
  "maxQueueSize": 200000,
  "maxLogDays": 7,
  "maxLogRecords": 10000,
  "enableVacuum": false,
  "useInMemoryDb": false,
  "sqliteDbPath": "querylogs.db",
  "connectionString": "Data Source='{sqliteDbPath}'; Cache=Shared;"
}

Runtime behavior

  1. Queries are buffered in a bounded channel.
  2. A background consumer thread bulk inserts records into SQLite.
  3. A periodic cleanup timer removes old records.
  4. If enableVacuum is enabled and cleanup deleted records, the database is vacuumed.

Risks / operational notes

  • Queue overflow drops writes (DropWrite behavior).
  • SQLite write contention can affect high traffic deployments.
  • In-memory mode does not persist across restarts.

Troubleshooting

  • Confirm the database path is writable.
  • Confirm connectionString still contains the {sqliteDbPath} token.
  • Check server logs for SQLite errors if logging stops.