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.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Parameterized queries prevent SQL injection. TLS/SSL support including client certificates. SCRAM-SHA-256 auth by default on modern PostgreSQL. Go memory safety.
⚡ 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
Authentication
Library — no external auth. PostgreSQL credentials via DSN or pgxpool.Config. Supports password, md5, scram-sha-256, and certificate auth.
Pricing
MIT-licensed open source Go module.
Agent Metadata
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).
Scores are editorial opinions as of 2026-03-06.