pq

A pure Go PostgreSQL driver for Go's standard database/sql package.

Library
Go
vv1.12.3
9,967 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
63 /100 Good
Development Activity 40
Maintenance 40
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
83 /100 Excellent
Architecture 84
Code Quality 85
Innovation 82
Learning Curve 80

lib/pq is a mature, pure-Go PostgreSQL driver that plugs directly into Go’s standard library database/sql interface. Registering it with a blank import lets you open a postgres connection and run queries with the same API you would use for any other SQL database, with no cgo or external C bindings required.

Beyond the basics it covers the parts of the PostgreSQL wire protocol that real applications need: TLS/SSL connections, PASSWORD/MD5/SCRAM-SHA-256 (and optional Kerberos) authentication, high-throughput COPY FROM STDIN bulk imports, asynchronous LISTEN/NOTIFY notifications, array and hstore type support, and libpq-compatible connection strings in both key=value and URL form.

What You Get

  • A drop-in postgres driver for database/sql, registered with a single blank import.
  • libpq-compatible connection strings in key=value and postgres:// URL form, including any run-time parameter.
  • Built-in TLS/SSL plus PASSWORD, MD5, and SCRAM-SHA-256 authentication (Kerberos via a separate module).
  • Bulk data loading through COPY FROM STDIN and asynchronous LISTEN/NOTIFY via pq.Listener.
  • Rich typed error values (pq.Error) exposing SQLSTATE codes, detail, hint, and source context.

Common Use Cases

  • Connecting a Go web service or API server to a PostgreSQL database through database/sql.
  • Streaming large datasets into PostgreSQL efficiently with COPY bulk imports.
  • Building event-driven features on top of PostgreSQL LISTEN/NOTIFY notifications.
  • Handling PostgreSQL-specific errors precisely by inspecting SQLSTATE codes.

Under The Hood

Architecture — pq is organized as a flat root package implementing the database/sql/driver contract, with conn.go handling the connection lifecycle and message loop, connector.go exposing the modern driver.Connector/Config path, copy.go implementing COPY-protocol streaming, notify.go providing the pq.Listener notification loop, and encode.go/array.go handling type encoding; supporting concerns are split into subpackages such as oid (type OIDs), scram (SCRAM-SHA-256), pqerror (SQLSTATE codes), hstore, and auth/kerberos, keeping optional dependencies out of the core.

Tech Stack — Written in pure Go (targeting go 1.23 per go.mod) with zero third-party runtime dependencies, relying solely on the standard library’s database/sql, crypto/tls, and net packages to speak the PostgreSQL wire protocol directly rather than binding to libpq via cgo.

Code Quality — The project is well tested, with 17 _test.go files covering connections, the connector, arrays, encoding, errors, COPY, SSL, and notifications, plus fuzz tests and runnable examples; tests execute against a real PostgreSQL instance (Docker compose provided) and the codebase carries typed error values and extensive doc comments.

API Design — The public surface is intentionally minimal and idiomatic: most users interact only through database/sql after a blank import, with pq.Config/NewConnectorConfig, pq.Listener, and pq.Error available for advanced needs. Package-level documentation in doc.go is thorough, and the libpq-compatible connection strings make the driver approachable for anyone familiar with PostgreSQL.

Used by 39 apps in this directory

Go
38%
MIT

ezBookkeeping

Invoicing Finance

5,814

Lightweight self-hosted personal finance manager with AI receipt scanning, multi-currency support, and MCP integration for complete data privacy.

View details
88
Repo Health
80
Technical
71
Dependency
Built with
Go 38%
Vue 33%
TypeScript 25%
Updated 6 days ago
Go
51%
MIT

Fathom Lite

Analytics

8,019

A simple, self-hosted website analytics tool built with Go and Preact that lets you understand your traffic without handing data to third parties.

View details
47
Repo Health
67
Technical
67
Dependency
Built with
Go 51%
JavaScript 31%
CSS 15%
Updated 7 months ago
Go
66%
AGPL 3.0

Fider

Customer Support · Product Management

4,586

Open-source feedback portal where customers submit, vote on, and track feature requests so product teams build what actually matters.

View details
88
Repo Health
85
Technical
65
Dependency
Built with
Go 66%
TypeScript 28%
Updated 1 weeks ago
Go
52%
AGPL 3.0

Filestash

File Storage

14,824

A self-hosted file management platform that unifies access to S3, SFTP, SMB, FTP, WebDAV, NFS, Git, SharePoint, and 20+ other storage backends through a single extensible web interface.

View details
79
Repo Health
67
Technical
67
Dependency
Built with
Go 52%
JavaScript 34%
Updated 1 weeks ago
TypeScript
54%
Other

Focalboard

Collaboration · Productivity · Project Management

26,522

Self-hosted, open source project management with Kanban, table, gallery, and calendar views — a privacy-first alternative to Trello, Notion, and Asana.

View details
56
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 54%
Go 40%
Updated 5 months ago
Go
91%
Apache 2.0

Gatus

Devops · Monitoring

12,386

Developer-oriented health dashboard with active endpoint probing, multi-protocol checks, and 40+ alerting integrations so you know about failures before your users do.

View details
84
Repo Health
84
Technical
75
Dependency
Built with
Go 91%
Updated 1 weeks ago
Go
83%
MIT

Gitea

Developer Tools · Devops · Project Management

58,668

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
64
Dependency
Built with
Go 83%
Updated 5 days ago
TypeScript
47%
AGPL 3.0

Grafana

Analytics · Monitoring

77,469

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 47%
Go 47%
Updated 5 days ago
Go
69%
Other

Hanko

Authentication · Security

9,045

Open source, self-hostable authentication platform with passkeys, SAML SSO, and OAuth — the privacy-first alternative to Auth0 and Clerk.

View details
90
Repo Health
81
Technical
66
Dependency
Built with
Go 69%
TypeScript 27%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers