Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(server): improve statement timeout and parameter handling #910

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tjhanley
Copy link

@tjhanley tjhanley commented Feb 25, 2025

  • Add statement timeout configuration at pool level (pools.<pool_name>.statement_timeout)
  • Add logging for statement timeout configuration during pool initialization
  • Improve sync_parameters method to handle statement timeout consistently
  • Document statement timeout configuration in CONFIG.md
  • Change string initialization from String::from() to String::new()
  • Maintain cleanup state until connection check-in for proper connection pooling

The statement timeout setting leverages PostgreSQL's native statement_timeout parameter, allowing the database to handle query termination automatically. This ensures reliable timeout enforcement directly at the database level, rather than managing timeouts in the connection pooler. Pool-level settings take precedence over user-level settings for consistent timeout enforcement across all pool users.


Screenshot 2025-02-25 at 12 50 17 PM


Connecting to the Postgres instance through PGCat connection pooler.

Minimal Config

[general]

host = "0.0.0.0"
port = 6433
admin_username = "pgcat"
admin_password = "pgcat"

[pools.pgml]
statement_timeout = 30000

[pools.pgml.users.0]
username = "postgres"
password = "postgres"
pool_size = 10
min_pool_size = 1
pool_mode = "transaction"

[pools.pgml.shards.0]
servers = [
  ["127.0.0.1", 28815, "primary"]
]
database = "postgres"
SELECT 
    state,
    current_setting('statement_timeout') AS statement_timeout
FROM pg_stat_activity
WHERE state = 'active';

state	statement_timeout
active	30s

Removing the option from the configuration yields this in the config.

2025-02-25T20:59:05.014649Z  INFO ThreadId(01) pgcat::config: [pool: pgcattest] Statement timeout: 0
SELECT 
    state,
    current_setting('statement_timeout') AS statement_timeout
FROM pg_stat_activity
WHERE state = 'active';

state	statement_timeout
active	0

@tjhanley tjhanley force-pushed the tjh/add-statement-timout-to-server branch 4 times, most recently from 8f6fa26 to bc4f28a Compare February 26, 2025 00:06
@montanalow montanalow requested a review from drdrsh February 26, 2025 01:18
- Add statement timeout configuration at pool level (pools.<pool_name>.statement_timeout)
- Add logging for statement timeout configuration during pool initialization
- Improve sync_parameters method to handle statement timeout consistently
- Document statement timeout configuration in CONFIG.md
- Change string initialization from String::from() to String::new()
- Maintain cleanup state until connection check-in for proper connection pooling

The statement timeout setting leverages PostgreSQL's native statement_timeout
parameter, allowing the database to handle query termination automatically.
This ensures reliable timeout enforcement directly at the database level,
rather than managing timeouts in the connection pooler. Pool-level settings
take precedence over user-level settings for consistent timeout enforcement
across all pool users.
@tjhanley tjhanley force-pushed the tjh/add-statement-timout-to-server branch from bc4f28a to 412bf4e Compare February 26, 2025 18:41
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.

1 participant