pgx: High-Performance PostgreSQL Driver
pgxpool, Copy protocol, and batch queries
What is pgx?
github.com/jackc/pgx/v5 is a PostgreSQL-specific Go driver with a native API that supports advanced PostgreSQL features unavailable in database/sql: COPY protocol, notifications, prepared statement caching, and more.
Connecting with pgx
Use pgx's native pool or database/sql compatibility layer:
// Native pgx pool
pool, err := pgxpool.New(ctx, "postgres://user:pass@localhost/mydb")
if err != nil { log.Fatal(err) }
defer pool.Close()All lessons in this course
- database/sql and Drivers
- sqlx: Struct Scanning and Named Queries
- pgx: High-Performance PostgreSQL Driver
- Transactions and Migrations