ged/ruby-pg logo

ged/ruby-pg

Free

A PostgreSQL client library for Ruby

FreeFree tier
Type
Open Source

About ged/ruby-pg

Pg is the Ruby interface to the PostgreSQL RDBMS, supporting PostgreSQL 10 and later. It provides a native Ruby client library that allows developers to connect to PostgreSQL databases, execute SQL queries, and process results. The library is available as a binary gem (with libpq built-in) for major platforms including x86_64-linux, aarch64-linux, arm64-darwin, and x64-mingw-ucrt, and can also be installed from source when needed. Binary gems are pre-built and do not require system libpq, simplifying deployment. The library is actively maintained on GitHub with over 870 stars and supports various installation methods through RubyGems. Example usage demonstrates connecting to a database and querying current connections.

Key Features

Ruby interface to PostgreSQL RDBMS
Supports PostgreSQL version 10 and later
Binary gems with built-in libpq for common platforms (x86_64-linux, aarch64-linux, arm64-darwin, x64-mingw-ucrt)
Source gem available for custom builds
Alpine Linux support via gcompat on binary gems
Easy installation via RubyGems: gem install pg
Force source gem with gem install pg --platform ruby
Supports Bundler for multi-platform dependencies
Connection options retrieval from LDAP (source gem only)

Pros & Cons

Pros
  • Easy installation via gem with pre-built binary gems for multiple platforms
  • Active maintenance with 870+ stars and 193 forks on GitHub
  • Binary gems eliminate need for system libpq installation
  • Supports cross-platform development (Linux, macOS, Windows)
  • Well-documented with example code and configuration guides
Cons
  • LDAP connection options not supported in binary gems
  • Requires Ruby 2.7+ and PostgreSQL 10+
  • Source gem installation may require libpq headers and pg_config
  • Binary gems on Alpine Linux need additional gcompat package

Best For

Building Ruby applications requiring PostgreSQL database connectivityData persistence in Ruby web frameworks (e.g., Rails, Sinatra)Database administration scripts and tools written in RubyReplacing other PostgreSQL adapters with a native interface

FAQ

What versions of PostgreSQL does ruby-pg support?
It works with PostgreSQL 10 and later.
How do I install ruby-pg?
Install via `gem install pg`. By default, a binary gem specific to your platform is installed. To force the source gem, run `gem install pg --platform ruby`. You may need to specify the path to pg_config.
What are the Ruby version requirements?
Ruby 2.7 or newer is required.
Is ruby-pg compatible with Alpine Linux?
Yes, binary gems for x86_64-linux and aarch64-linux run on Alpine Linux, but require the package `gcompat`. Native gems for *-linux-musl work without that dependency.