explaingit

jackc/pgx

13,792GoAudience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((pgx))
    What it does
      PostgreSQL driver
      Wire protocol toolkit
      Connection pooling
    Key Features
      LISTEN NOTIFY
      COPY bulk load
      Batch queries
      70 data types
    Tech Stack
      Go
      No C deps
    Ecosystem
      Standard db adapter
      Logical replication
      Test mock server
    Audience
      Go developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Connect a Go application to PostgreSQL with higher performance and more features than the standard database driver.

USE CASE 2

Use PostgreSQL LISTEN/NOTIFY to push real-time events from the database to a Go service.

USE CASE 3

Bulk-load large datasets into PostgreSQL at high speed using the COPY protocol.

USE CASE 4

Build a database proxy, connection pooler, or mock PostgreSQL server using the low-level wire protocol packages.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 30min

Requires a running PostgreSQL server, the Go package itself installs with a single go get command and has no system library dependencies.

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to connect to PostgreSQL using pgx v5 in Go and run a SELECT query that returns typed rows.
Prompt 2
I want to listen for PostgreSQL NOTIFY events in my Go app using pgx. Give me a working example with a goroutine that handles incoming notifications.
Prompt 3
How do I bulk-insert 100,000 rows into a PostgreSQL table as fast as possible using the pgx COPY protocol?
Prompt 4
Write a Go function using pgx that sends 5 queries in a single round trip using batch queries and reads all the results.
Open on GitHub → Explain another repo

← jackc on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.