#!/usr/bin/env python3 """Print the effective PostgreSQL timeouts and pool limits. Run inside the API container: docker compose exec -T api python student-tests/pool_settings.py """ from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from app import db def main() -> None: db.pool().open(wait=True, timeout=5) db.apply_migrations() with db.pool().connection() as conn: statement = conn.execute("SHOW statement_timeout").fetchone()["statement_timeout"] idle = conn.execute("SHOW idle_in_transaction_session_timeout").fetchone()[ "idle_in_transaction_session_timeout" ] lock = conn.execute("SHOW lock_timeout").fetchone()["lock_timeout"] stats = db.pool().get_stats() print("statement_timeout =", statement) print("idle_in_transaction_session_timeout =", idle) print("lock_timeout =", lock) print("pool_min =", stats["pool_min"]) print("pool_max =", stats["pool_max"]) print("pool_size =", stats["pool_size"]) print("pool_available =", stats["pool_available"]) print("PASS: bounded pool and SQL timeouts are active") if __name__ == "__main__": main()