pgx (Go PostgreSQL)

The most feature-complete and performant PostgreSQL driver for Go. pgx provides both a native pgx API with rich type support (pgtype.Text, JSONB, arrays, Hstore) and a standard database/sql driver interface. Supports PostgreSQL-specific features — LISTEN/NOTIFY, COPY FROM/TO, prepared statement caching, and batch queries — that database/sql doesn't expose. More performant and featureful than lib/pq for production PostgreSQL workloads.

Evaluated Mar 06, 2026 (0d ago) vv5
Homepage ↗ Repo ↗ Developer Tools go postgresql database driver sql pgpool open-source typed
⚙ Agent Friendliness
64
/ 100
Can an agent use this?
🔒 Security
87
/ 100
Is it safe for agents?
⚡ Reliability
84
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
82
Auth Simplicity
85
Rate Limits
88

🔒 Security

TLS Enforcement
92
Auth Strength
88
Scope Granularity
82
Dep. Hygiene
90
Secret Handling
85

Parameterized queries prevent SQL injection. TLS/SSL support including client certificates. SCRAM-SHA-256 auth by default on modern PostgreSQL. Go memory safety.

⚡ Reliability

Uptime/SLA
88
Version Stability
85
Breaking Changes
75
Error Recovery
88
AF Security Reliability

Best When

You're building a Go application on PostgreSQL and want the best performance, richest type support, and access to PostgreSQL-specific features not available via database/sql.

Avoid When

You need multi-database support or are using an ORM that manages the driver — GORM with pgx underneath provides the balance of ORM ergonomics with pgx performance.

Use Cases

  • Connect Go agent services to PostgreSQL with the highest performance and PostgreSQL-specific feature support available
  • Use LISTEN/NOTIFY for event-driven agent architectures — receive real-time notifications from PostgreSQL without polling
  • Execute COPY FROM for bulk data ingestion into agent PostgreSQL databases — orders of magnitude faster than individual INSERTs
  • Leverage PostgreSQL-specific types (JSONB, arrays, UUID, geometry) with pgx's rich pgtype system for agent data modeling
  • Use pgxpool for connection pooling in high-throughput Go agent services — managed pool with health checking and automatic reconnection

Not For

  • MySQL, SQLite, or other databases — pgx is PostgreSQL-only; use database/sql with appropriate drivers for other databases
  • Teams wanting ORM abstractions — use GORM or sqlx with pgx as the underlying driver for higher-level query building
  • Simple applications where lib/pq is already working — migration to pgx adds value mainly for production workloads needing PostgreSQL-specific features

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Library — no external auth. PostgreSQL credentials via DSN or pgxpool.Config. Supports password, md5, scram-sha-256, and certificate auth.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT-licensed open source Go module.

Agent Metadata

Pagination
cursor
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • pgx v5 uses pgconn.PgError for database errors — errors.As() required to extract PostgreSQL error codes; the old v4 pgx.PgError type is removed in v5
  • pgxpool.Pool.Acquire() must be paired with conn.Release() or used in defer — forgetting to release connections exhausts the pool in agent connection-heavy code
  • The native pgx API and database/sql adapter have different semantics — mixing pgx.Rows and sql.Rows iterators in the same codebase causes confusion; standardize on one API
  • LISTEN/NOTIFY connections cannot be used for regular queries while waiting — maintain a separate dedicated connection for LISTEN in agent event-driven architectures
  • pgx prepared statement caching can cause 'prepared statement already exists' errors across connection pool connections — use StatementCacheCapacity 0 to disable or ensure proper cache eviction
  • pgtype.Numeric and other custom types require explicit scanning via pgx's Scan() with typed destination variables — using simple Go types (float64) for PostgreSQL NUMERIC may lose precision

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for pgx (Go PostgreSQL).

$99

Scores are editorial opinions as of 2026-03-06.

5215
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered