Skip to content

feat: add support for psycopg - #1452

Open
kgala2 wants to merge 16 commits into
GoogleCloudPlatform:mainfrom
kgala2:feat-psycopg
Open

feat: add support for psycopg#1452
kgala2 wants to merge 16 commits into
GoogleCloudPlatform:mainfrom
kgala2:feat-psycopg

Conversation

@kgala2

@kgala2 kgala2 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

This PR adds support for the psycopg (v3) database driver for PostgreSQL.

Key Changes:

  • Psycopg Driver Wrapper: Implemented google/cloud/sql/connector/psycopg.py to wrap psycopg connections.
  • Single-Threaded Proxy Loop: Designed and implemented a single-threaded selectors-based proxy in psycopg.py to manage bidirectional data transfer between the local Unix socket and the remote mTLS secure socket. This resolves potential ssl.SSLSocket thread-safety deadlocks that can occur with multi-threaded proxy designs.
  • Unit Tests: Added comprehensive unit tests in tests/unit/test_psycopg.py covering:
    • Happy-path bidirectional data transfer.
    • SSL pending bytes forwarding.
    • Proxy timeouts, remote EOF disconnects, and handshake failure cleanup.
    • Socket read/write error handling paths.
  • System Tests: Added E2E system tests in tests/system/test_psycopg_connection.py and tests/system/test_psycopg_iam_auth.py to verify real database connections (including with IAM authentication).
  • Documentation: Updated README.md to list psycopg as a supported driver and provided installation and usage examples.

Fixes #214

@kgala2
kgala2 marked this pull request as ready for review August 4, 2026 20:32
@kgala2
kgala2 requested a review from a team as a code owner August 4, 2026 20:32
@kgala2
kgala2 marked this pull request as draft August 4, 2026 20:33
@kgala2
kgala2 marked this pull request as ready for review August 4, 2026 20:49
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.

Add support for psycopg2 driver.

3 participants