GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Query Tool retains large result sets after connection closure, causing excessive memory usage · Issue #10890 · pgadmin-org/pgadmin4

Query Tool retains large result sets after connection closure, causing excessive memory usage #10890

New issue
Copy link
New issue
Copy link
Backlog
Backlog
Query Tool retains large result sets after connection closure, causing excessive memory usage#10890
Copy link
Labels
Bug

Description

@Ben-Cho
Ben-Cho
opened on Nov 27, 2026
Issue body actions

Description

We observed significant memory retention in pgAdmin 4 v9.13 running in server mode.

The Gunicorn worker retained PostgreSQL query results through AsyncDictCursor objects, even though their associated database connections were already closed and the corresponding pgAdmin sessions had been inactive for over 30 minutes.

Explicitly closing just two retained cursors reduced the worker's RSS by approximately 2.12 GiB, without restarting pgAdmin.

Repeated UnicodeDecodeError exceptions during connection cleanup may contribute to this behavior.

Environment

  • pgAdmin: 4 v9.13 (dpage/pgadmin4:9.13)
  • Deployment: Docker, server mode
  • Python: 3.14.3
  • Driver: psycopg3
  • Authentication: Internal, multiple users
  • Gunicorn: 1 worker, 25 threads
  • Container memory limit: 4 GiB
  • Worker uptime at investigation: 39 days

Observed behavior

Direct inspection of the running Gunicorn worker revealed:

  • Worker RSS: 3,604,920 kB
  • Retained pgAdmin sessions: 20
  • ServerManager objects: 62
  • Connection objects: 227
  • Open PostgreSQL connections: 14
  • Closed connection objects still referenced: 213
  • Closed connections retaining an open AsyncDictCursor: 54
  • PostgreSQL result objects retained by those cursors: 54
  • Total rows referenced by retained results: 7,772,106

Of the 54 retained cursors, 50 belonged to sessions inactive for at least 30 minutes.

Experimental confirmation

We selectively closed two cursors associated with closed database connections, removed their references from the corresponding Connection objects, and invoked Python garbage collection.

First cursor cleanup:

  • Retained rows: 2,589,520
  • Worker RSS before: 3,604,948 kB
  • Worker RSS after: 2,490,444 kB
  • RSS reduction: 1,114,504 kB

Second cursor cleanup:

  • Retained rows: 2,589,022
  • Worker RSS before: 2,490,472 kB
  • Worker RSS after: 1,385,840 kB
  • RSS reduction: 1,104,632 kB

Total RSS reduction: approximately 2.12 GiB.

The reduction persisted after cleanup. A subsequent inspection also confirmed that the first cursor and its 2,589,520 rows were no longer retained.

This directly demonstrates that retained query results accounted for a substantial portion of the worker's memory consumption.

Related cleanup exception

The logs also contained 175 UnicodeDecodeError exceptions in 24 hours, including 17 in one hour, originating from POST /misc/cleanup.

Relevant traceback:

pgadmin/misc/__init__.py, in cleanup
    driver.ping()

pgadmin/utils/driver/__init__.py, in ping
    DriverRegistry._objects[type].gc_timeout()

pgadmin/utils/driver/psycopg3/__init__.py, in gc_timeout
    mgr.release()

pgadmin/utils/driver/psycopg3/server_manager.py, in release
    conn.cancel_transaction(conn.conn_id[5:])

pgadmin/utils/driver/psycopg3/connection.py, in cancel_transaction
    password = decrypt(password, crypt_key).decode()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcb in position 1: invalid continuation byte

In ServerManager.release(), conn.cancel_transaction() is called before conn._release(), without exception handling around the cancellation.

Consequently, a decryption exception can prevent the remaining connection cleanup operations from running.

Additionally, gc_timeout() iterates over managers belonging to different sessions, while get_crypt_key() retrieves a key associated with current_user.id. This may lead to a key mismatch when one user's request triggers cleanup of another user's connections.

The connection between these decryption exceptions and the specific retained result sets has not been conclusively established.

Relevant code

  • [psycopg3/connection.py](https://github.com/pgadmin-org/pgadmin4/blob/REL-9_13/web/pgadmin/utils/driver/psycopg3/connection.py) — cancel_transaction(), _release() and release_async_cursor()
  • [psycopg3/server_manager.py](https://github.com/pgadmin-org/pgadmin4/blob/REL-9_13/web/pgadmin/utils/driver/psycopg3/server_manager.py) — release()
  • psycopg3/init.py — gc_timeout()
  • [master_password.py](https://github.com/pgadmin-org/pgadmin4/blob/REL-9_13/web/pgadmin/utils/master_password.py) — get_crypt_key()

Expected behavior

  • Query results and associated cursor resources should be released when their connections are closed or their sessions are cleaned up.
  • An exception while cancelling one transaction should not prevent cleanup of unrelated connections.
  • Cleanup should not attempt to decrypt another user's stored connection password using the current request user's key.

Reproduction status

Observed repeatedly in a long-running, multi-user pgAdmin instance using Query Tool with large result sets.

A minimal standalone reproduction has not yet been established. The memory retention and its release through targeted cursor cleanup were confirmed directly in the running process.

Related issue

Possibly related to #6120, which reported a similar UnicodeDecodeError during connection cleanup and was closed as fixed in v7.1.

The present report adds direct evidence of substantial SQL result memory retention in v9.13.

Activity

  1. Ben-Cho
    added
    Bug
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.