Skip to content

SQL Logs

Menu: Database → SQL Logs
Deep link: /_Admin/database/sql-logs?SiteId={siteGuid}

SQL logs show SQL statements executed by site scripts through k.DB.sqlite / k.DB.mysql / k.DB.sqlServer: statement text, parameters, duration, and database type for troubleshooting and auditing. This page is read-only observation; it does not delete or edit logs, and there is no corresponding k.* write API.

Permissions

Viewing this page and list data: database·log (the log action on the database feature).
The Enable toggle on the toolbar right saves site settings and usually requires site edit-class permissions (same as saving site configuration).

What is logged

LoggedNot logged
SQL from k.DB.sqlite.query / execute, etc.IndexedDB tables (k.DB.indexedDb) operations
SQL from k.DB.mysql, k.DB.sqlServerKey-value storage (k.DB.keyValue)
SQL from admin SQLite / MySQL / SQL Server maintenance when routed through the same executor (if applicable)Any SQL when SQL logging is disabled

You must enable SQL logging on the site first (see Enable SQL logging); only SQL produced after that is written to the log.

How to Open

  1. In Edit Menu, check Database → SQL Logs.
  2. Open Database → SQL Logs in the left sidebar.
SQL logs page

Enable SQL logging

Site-level switch enableSqlLog; both locations are equivalent (changing one is enough):

LocationPath
This page toolbarEnable toggle on the right; saves the site immediately
Site settings → Advanced/_Admin/system/settings?SiteId={siteGuid}&name=advance, SQL logging item

When disabled, new script SQL is not written to the log; existing historical weekly data can still be viewed by week.

SQL logs filters and enable toggle

Toolbar left to right:

ControlDescription
WeekSelect log file by calendar week; option text is yyyy-MM-dd~yyyy-MM-dd (week start/end). Only weeks where the current site has entries are listed; if none yet, defaults to current week
TypeOptional SQLite, MySQL, SQLServer (maps to sqlite / mysql / sqlserver); clear for all types
KeywordFuzzy match in SQL body (case-insensitive); ~1 second debounce after input; clear to refresh
EnableSee Enable SQL logging

Changing Week, Type, or keyword re-requests SqlLog/List and returns to page 1.

Log list

Default pagination 50 rows per page (KTable pagination at bottom).

ColumnDescription
TypeDatabase source, e.g. sqlite, mysql, sqlserver
Date timeExecution time (site timezone)
Execution timeDuration in ms
ContentSQL statement summary (truncated in table when long)
ParametersSerialized parameter object; empty when none or null
Row DetailsOpens details dialog when data exists

When the week has no records, the table shows No data (logging must be enabled and the site must have executed k.DB.sqlite etc.).

SQL log list

Details dialog

Click the row eye icon. Shows full Type, Date time, Execution time, and two full text blocks:

  1. SQL statement (with line breaks)
  2. Parameters (JSON or other serialized form)

Use to copy the full statement or compare parameters in slow-query scenarios.

How logs are produced

When scripts access relational databases and EnableSqlLog is true, the executor asynchronously writes to server log files partitioned by week (under site AppData SqlLog, filenames like {yearWeek}.log). Writes and list queries filter by site ID; you only see this site’s records.

Example (after logging is enabled):

typescript
k.DB.sqlite.query("SELECT * FROM logs WHERE id = @id", { id: 1 })
k.DB.sqlite.execute("INSERT INTO logs (msg) VALUES (@msg)", { msg: "ok" })

For MySQL / SQL Server, configure connections under Service integrations (/system/config), then execute via k.DB.mysql / k.DB.sqlServer to see logs of the matching type.

Admin table maintenance

Whether SQLite tables list/column/data admin APIs share the same execution chain as script k.DB.sqlite depends on the environment. When troubleshooting script SQL, rely on Type and Content on this page; if admin actions produce no log, confirm execution goes through k.DB.* and logging is enabled.

Typical workflow

  1. Turn on SQL logging under Advanced or on this page.
  2. Reproduce the issue (page or job that runs k.DB.sqlite, etc.).
  3. Select the week, narrow by type / keyword.
  4. Open Details, copy SQL and parameters, verify in Code or a database tool.
  5. Long-term enablement in production may increase I/O and disk use; turn off Enable after troubleshooting.
DocDescription
Database overviewMenus and permissions
SQLite tablesBuilt-in SQLite and CSV
k.DB.sqliteScript SQL API
k.DBDatabase overview