Skip to content

feat: add query_log_stdout config for pgcat-style query logging#1015

Open
marcomicera wants to merge 1 commit into
pgdogdev:mainfrom
marcomicera:query_log_stdout
Open

feat: add query_log_stdout config for pgcat-style query logging#1015
marcomicera wants to merge 1 commit into
pgdogdev:mainfrom
marcomicera:query_log_stdout

Conversation

@marcomicera
Copy link
Copy Markdown

Summary

Adds a query_log_stdout general config option that logs every query to stdout in pgcat-style format: [pool: db][user: user] query.

  • Configurable via pgdog.toml or PGDOG_QUERY_LOG_STDOUT
  • Defaults to false
  • Logs at the start of query parsing so queries are captured even when the parser is bypassed

Test plan

  • Run pgdog with query_log_stdout = true and confirm queries appear in logs

Log every query to stdout when enabled via pgdog.toml or
PGDOG_QUERY_LOG_STDOUT, using format [pool: db][user: user] query
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 28, 2026

CLA assistant check
All committers have signed the CLA.

@marcomicera marcomicera changed the title feat: add query_log_stdout config for pgcat-style query logging feat: add query_log_stdout config for pgcat-style query logging May 28, 2026
@marcomicera marcomicera marked this pull request as ready for review May 28, 2026 09:56
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pgdog/src/frontend/router/parser/query/mod.rs 25.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@marcomicera
Copy link
Copy Markdown
Author

Adding tests to cover these 6 missing lines... 👨‍💻

#[serde(default)]
pub query_log: Option<PathBuf>,

/// Log queries to stdout (pgcat-style). Format: `[pool: db][user: user] query`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the db/user at the end to match our existing log format. Not sure if it's right, but at least it's consistent.

SELECT * FROM users WHERE id = $1 [database: oranges, user: apples]


/// Parse a query and return a command.
pub fn parse(&mut self, context: RouterContext) -> Result<Command, Error> {
if config().config.general.query_log_stdout {
Copy link
Copy Markdown
Collaborator

@levkk levkk May 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this somewhere at the top of QueryEngine::handle, in its own function. The parser is not guaranteed to be used if, for example, query_parser = "off" in the config.

The query will be available as:

if context.query_log_stdout {
  if let Ok(Some(query)) = context.client_request.query() {
      info!("{} [database: {}, user: {}]", query.query(), ...);
   }
}

Also, try to follow the same pattern as other settings, e.g. load them at request start only here:

let config = config::config();

Loading the config (ArcSwap + Arc clone) is effectively free, but not entirely, so we try to do it once per query at most.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants