DEV.co
Open-Source Databases · go-pg

pg

go-pg is a PostgreSQL client and ORM for Go that emphasizes PostgreSQL-specific features and performance. The project is in maintenance mode with only critical issues addressed; the maintainers recommend new projects use Bun, which offers similar functionality across multiple databases.

Source: GitHub — github.com/go-pg/pg
5.8k
GitHub stars
413
Forks
Go
Primary language
BSD-2-Clause
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorygo-pg/pg
Ownergo-pg
Primary languageGo
LicenseBSD-2-Clause — OSI-approved
Stars5.8k
Forks413
Open issues121
Latest releasev10.15.1 (2026-05-29)
Last updated2026-05-29
Sourcehttps://github.com/go-pg/pg

What pg is

go-pg provides struct-based ORM mapping, support for PostgreSQL types (arrays, hstore, JSONB, composite types), connection pooling with circuit breaker, transactions, prepared statements, and bulk operations. It includes relationship support (has-one, belongs-to, has-many, many-to-many) and can generate schema from structs.

Quickstart

Get the pg source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/go-pg/pg.gitcd pg# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

PostgreSQL-focused backends

Applications that need deep PostgreSQL feature integration (arrays, hstore, JSONB, composite types) and can commit to a single-database strategy benefit from go-pg's specialized optimizations.

Existing Go codebases

Teams with established go-pg deployments can continue using it for maintenance and incremental updates without immediate migration pressure, given ongoing critical-issue support.

Performance-critical ORM layers

Projects requiring bulk inserts/updates, connection pooling with circuit breaker, and prepared statement support can leverage go-pg's performance-oriented design.

Implementation considerations

  • All struct fields are nullable by default; use `pg:"notnull"` and `pg:"use_zero"` tags carefully to align Go zero-value semantics with SQL constraints.
  • Relationship loading (has-one, belongs-to, has-many, many-to-many) requires explicit `.Relation()` calls; N+1 queries are possible if not managed deliberately.
  • The library supports transactions and context-based cancellation; ensure timeout and context-cancellation patterns are consistently applied in error-prone code paths.
  • Bulk operations (insert, update, delete) are available; verify performance gains via profiling before assuming they're faster than single-row operations for your workload.
  • Schema generation from structs is supported but review generated DDL for production use; rely on migrations for version control and audit trails.

When to avoid it — and what to weigh

  • Multi-database strategy required — If your roadmap includes MySQL, MariaDB, or SQLite, go-pg is PostgreSQL-only. Bun (the recommended successor) supports all four and should be evaluated instead.
  • New project starting today — The README explicitly states go-pg is in maintenance mode and recommends Bun for new development. Choosing go-pg for a greenfield project introduces technical debt and limits future flexibility.
  • Rapid feature velocity needed — Only critical issues are addressed in maintenance mode. If you need regular ORM improvements, query optimization features, or framework integrations, an actively developed ORM is more appropriate.
  • Uncertainty about PostgreSQL commitment — If your database choice is not yet finalized or subject to change, the single-database focus makes go-pg risky. Use an ORM with multi-database support or defer ORM selection.

License & commercial use

BSD-2-Clause (Simplified License). This is an OSI-approved permissive license that permits commercial use, modification, and distribution with minimal restrictions (retain copyright notice and license text).

BSD-2-Clause is permissive and explicitly allows commercial use without royalties or restrictions. No secondary licenses detected. Suitable for closed-source and proprietary products. Consult legal counsel if integrating other dependencies with conflicting licenses.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceModerate
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Parameterized queries and prepared statements are available and should be used consistently. Context-based timeout support mitigates slowloris and resource-exhaustion risks. No known advisories mentioned in provided data. Review generated schema DDL before production deployment. Ensure network isolation and TLS configuration for PostgreSQL connections in security-critical environments. Circuit breaker and retry logic may mask transient failures; monitor for partial failures.

Alternatives to consider

Bun

Official successor with same design philosophy but multi-database support (PostgreSQL, MySQL, MariaDB, SQLite). Actively developed. Recommended by go-pg maintainers for new projects.

sqlc

Type-safe SQL code generation from schema. Avoids ORM overhead and forces explicit query design. Suitable if you prefer hand-tuned SQL and compile-time safety over convenience.

GORM

Most popular Go ORM. Multi-database support, large community, frequent updates. More feature-rich but higher learning curve and potential over-abstraction.

Software development agency

Build on pg with DEV.co software developers

go-pg is stable for existing deployments but in maintenance mode. Confirm whether Bun or another ORM better fits your multi-database strategy and feature roadmap.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

pg FAQ

Is go-pg still actively developed?
No. It is in maintenance mode; only critical issues are addressed. The maintainers recommend Bun for new projects. Existing deployments can continue to rely on it for stability and critical patches.
Can I use go-pg with MySQL or SQLite?
No. go-pg is PostgreSQL-only. If multi-database support is needed, evaluate Bun or GORM instead.
How does go-pg handle NULL values?
All struct fields are nullable by default (mapped to SQL NULL if zero-valued). Use `pg:"notnull"` to enforce NOT NULL constraints and `pg:"use_zero"` to allow Go zero values as non-null data.
Does go-pg support migrations?
Not built-in. Use community packages like go-pg/migrations or robinjoseph08/go-pg-migrations, or external tools. Schema generation from structs is possible but should be validated before production use.

Custom software development services

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If pg is part of your open-source databases roadmap, our team can implement, customize, migrate, and maintain it.

Evaluating a PostgreSQL ORM for Go?

go-pg is stable for existing deployments but in maintenance mode. Confirm whether Bun or another ORM better fits your multi-database strategy and feature roadmap.