Skip to main content

PREQUEL-2025-0028

Datadog Postgres Check ExceptionLow
Impact: 2/10
Mitigation: 2/10

PREQUEL-2025-0028View on GitHub

Description

The Datadog Agent’s *Postgres* integration throws an uncaught Python\ntraceback while trying to run an `EXPLAIN (FORMAT JSON)` against a\nsampled query. After the first failure the underlying **psycopg2**\ncursor is closed, and every subsequent collection cycle logs\n\n```\nTraceback …\nFile \".../datadog_checks/postgres/explain_parameterized_queries.py\", …\npsycopg2.InterfaceError: cursor already closed\n```\n\nThe check status flips to **ERROR**, and query metrics / samples stop\nflowing.\n

Mitigation

1. **Disable parameterized-query explains** (quickest relief):\n\n ```yaml\n instances:\n - host: <db_host>\n port: 5432\n username: datadog\n password: ENC[...]\n dbm: true\n query_samples:\n explain_parameterized_queries: false\n ```\n Then `systemctl restart datadog-agent` (or recycle the pod).\n\n2. **Force simple-query protocol** in the app until you can upgrade: \n *Go pgx*: `PreferSimpleProtocol=true` | *JDBC*: `preferQueryMode=simple`.\n\n3. **Upgrade the Agent** to **≥ 7.64.0** (or the newest available); the\n Postgres integration now recreates the cursor after an `EXPLAIN`\n failure and better handles ambiguous operator errors.\n\n4. **Verify the helper function** exists and has permission:\n\n ```sql\n \\df+ datadog.explain_statement -- should return 1 row\n ```\n\n5. **Confirm check recovers**:\n\n ```bash\n datadog-agent status | grep postgres\n # should show \"OK\" and increasing \"Total Runs\"\n ``` \n

References