gitmyhub

pgx

Go ★ 14k updated 5h ago

PostgreSQL driver and toolkit for Go

A PostgreSQL driver and toolkit for Go that exposes PostgreSQL-specific features like bulk COPY, pub/sub notifications, batch queries, and 70+ data types without any C library dependencies.

Gosetup: easycomplexity 2/5

pgx is a PostgreSQL driver and toolkit written entirely in Go. It lets Go programs connect to and communicate with a PostgreSQL database, and it is written without any C dependencies, meaning it works cleanly in any Go environment without needing extra system libraries installed.

The core driver prioritizes performance and exposes PostgreSQL features that are not available through Go's standard database interface. That includes LISTEN and NOTIFY (a pub/sub system built into PostgreSQL), the COPY protocol for fast bulk data loading, batch queries that send multiple requests in one round trip, and support for about 70 PostgreSQL data types. It also includes a connection pool with hooks for custom setup logic, full control over TLS settings, and tracing and logging support. If you need to use it with libraries that expect the standard Go database interface, pgx provides an adapter for that too.

Beyond the driver itself, pgx ships a set of lower-level packages that implement the PostgreSQL wire protocol and type conversion logic. These packages exist so that other developers can build their own tools on top: things like database proxies, connection poolers, logical replication clients, or mock servers for testing. The repository even lists related companion libraries for those use cases, including one for logical replication and one that simulates a PostgreSQL server for tests.

The project supports the two most recent Go versions and PostgreSQL versions released in the past five years (currently Go 1.25+ and PostgreSQL 14+). It also runs tests against CockroachDB. Version 5 is the current stable release. A healthy ecosystem of third-party adapters has grown around the library, adding support for UUID types, decimal types, geographic data, OpenTelemetry tracing, and several logging frameworks.

If you are building a Go application that talks to PostgreSQL and you want direct access to PostgreSQL-specific features or need better throughput than the standard library offers, pgx is the most widely used option in the Go ecosystem.

Where it fits