-
-
Notifications
You must be signed in to change notification settings - Fork 86
Open
Description
DuckDB provides local configuration option that lets log all executed queries to file:
| Name | Description |
|---|---|
| log_query_path | Specifies the path to which queries should be logged (default: NULL, queries are not logged) |
When this setting is enabled and queries are executed through DuckDB.NET, the log file records only successful queries - failed queries are not logged. In contrast, when using the DuckDB CLI, both successful and failed queries are logged.
CLI behavior:
DuckDB v1.3.2 (Ossivalis) 0b83e5d2f6
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
D SET log_query_path = log_cli.txt;
D SELECT 1;
┌───────┐
│ 1 │
│ int32 │
├───────┤
│ 1 │
└───────┘
D SELECT 1 FROM;
Parser Error:
syntax error at or near ";"
LINE 1: SELECT 1 FROM;
^
D SELECT 1 FROM B;
Catalog Error:
Table with name B does not exist!
LINE 1: SELECT 1 FROM B;
^
D RESET log_query_path;
D .exit
cat .\log_cli.txt
SELECT 1;
SELECT 1 FROM B;Successful query and failed to execute query are logged. Didn't log failed to parse query.
DuckDB.NET behavior (DuckDBCommand):
// in public class DuckDBDataReaderTests(DuckDBDatabaseFixture db) : DuckDBTestBase(db)
[Fact]
public void LogSqlStatements()
{
var suffix = "origin";
var fileName = $"log_{suffix}.txt";
if (File.Exists(fileName))
{
File.Delete(fileName);
}
Command.CommandText = $"SET log_query_path = {fileName}";
_ = Command.ExecuteNonQuery();
Command.CommandText = "SELECT 1";
Command.ExecuteReader();
Command.CommandText = "SELECT 1 FROM";
try
{
Command.ExecuteReader();
}
catch { }
Command.CommandText = "SELECT 1 FROM B";
try
{
Command.ExecuteReader();
}
catch { }
File.Exists(fileName);
Command.CommandText = "RESET log_query_path";
Command.ExecuteReader();
var logs = File.ReadAllText(fileName);
logs.Contains("SELECT 1 FROM").Should().BeTrue();
}Logs
cat .\DuckDB.NET.Test\bin\Debug\net8.0\log_origin.txt
SELECT 1
RESET log_query_pathOnly successful queries were logged.
Metadata
Metadata
Assignees
Labels
No labels