Skip to content

Misshandling of Postgres Pools #98

@salmosri

Description

@salmosri

postgres-mcp doesn't properly manage database connection pools when using SSE (Server-Sent Events) transport.

Here's what happens:

  1. New pool per connection: Each time an MCP client connects via SSE, postgres-mcp creates a new database connection pool (pool-1, pool-2, pool-47, etc.)
  2. Pools get closed: After handling a request, the pool is closed but the reference remains
  3. Stale pool references: Subsequent requests try to use these closed pools, resulting in the error "the pool 'pool-47' is closed"
  4. No pool reuse: Instead of reusing a single connection pool across all SSE sessions, it creates new ones and doesn't clean up properly

This is a design flaw in how postgres-mcp handles SSE connections. The SSE transport is meant for long-lived connections, but postgres-mcp treats each request as isolated, creating this pool management issue.

Evidence from the logs:
ERROR Error executing query: Connection server.py:401
attempt failed: the pool 'pool-49' is
closed
ERROR Error executing query: Connection server.py:401
attempt failed: the pool 'pool-55' is
closed

The incrementing pool numbers (pool-49, pool-55, pool-67) show that new pools keep being created instead of reusing existing ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions