Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A git mirror of the 'pg' gem.

Octocat-spinner-32 ext Fix documentation for PG::Connection::conndefaults. September 23, 2013
Octocat-spinner-32 lib Fix documentation for PG::Connection::conndefaults. September 23, 2013
Octocat-spinner-32 misc Update windows cross compilation tasks to the latest Openssl+Postgres… June 17, 2012
Octocat-spinner-32 sample Whitespace cleanup March 26, 2013
Octocat-spinner-32 spec verify_clean_exec_status itself should leave a clean status. September 14, 2013
Octocat-spinner-32 .gemtest Converted to Hoe October 07, 2011
Octocat-spinner-32 .hgignore Add generated error codes file to the ignorelist July 17, 2013
Octocat-spinner-32 .hgsigs Added signature for changeset eed93df350a6 September 16, 2013
Octocat-spinner-32 .hgtags Added tag v0.17.0 for changeset 30da9c169efc September 16, 2013
Octocat-spinner-32 .hoerc Add the Gemfile to the list of files that don't have to be on the Man… September 16, 2013
Octocat-spinner-32 .irbrc Updated build system January 03, 2010
Octocat-spinner-32 .pryrc Rearranging classes under the PG namespace to be a better Ruby citizen January 24, 2012
Octocat-spinner-32 .rvm.gems Bump versions of dev dependencies March 12, 2013
Octocat-spinner-32 .rvmrc Test under Ruby 2.0.0 by default February 25, 2013
Octocat-spinner-32 .tm_properties Fix indent in project settings June 07, 2013
Octocat-spinner-32 .travis.yml Travis: Allow failures on rbx. July 19, 2013
Octocat-spinner-32 BSDL Add missing BSDL license file (fixes #108) February 09, 2012
Octocat-spinner-32 Contributors.rdoc Update Rafał Bigaj's email address in Contributors.rdoc at his request October 01, 2012
Octocat-spinner-32 Gemfile Add Gemfile for compat with rake-compiler-dev-box. August 14, 2013
Octocat-spinner-32 History.rdoc Bump minor version September 15, 2013
Octocat-spinner-32 LICENSE Updated/simplified authors/license sections of the README, API doc cl… January 24, 2012
Octocat-spinner-32 Manifest.txt Use inheritance to describe multiple types of PGErrors. May 18, 2013
Octocat-spinner-32 POSTGRES fix cross compilation of win32 binary gem, fix mixed case file naming January 27, 2012
Octocat-spinner-32 README-OS_X.rdoc More case-corrections January 27, 2012
Octocat-spinner-32 README-Windows.rdoc More case-corrections January 27, 2012
Octocat-spinner-32 README.ja.rdoc Update READMEs February 27, 2013
Octocat-spinner-32 README.rdoc Update README, add Lars as maintainer March 26, 2013
Octocat-spinner-32 Rakefile Add Gemfile for compat with rake-compiler-dev-box. August 14, 2013
Octocat-spinner-32 Rakefile.cross Use RbConfig::CONFIG['CC'] instead of ['host'] for determining cross August 15, 2013






Pg is the Ruby interface to the PostgreSQL RDBMS.

It works with PostgreSQL 8.4 and later.

A small example usage:

#!/usr/bin/env ruby

require 'pg'

# Output a table of current connections to the DB
conn = PG.connect( dbname: 'sales' )
conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
  puts "     PID | User             | Query"
result.each do |row|
    puts " %7d | %-16s | %s " %
      row.values_at('procpid', 'usename', 'current_query')

Build Status



  • Ruby 1.9.3-p392, or 2.0.0-p0.

  • PostgreSQL 8.4.x or later (with headers, -dev packages, etc).

It may work with earlier versions of Ruby/PostgreSQL as well, but those are not regularly tested.

How To Install

Install via RubyGems:

gem install pg

You may need to specify the path to the 'pg_config' program installed with Postgres:

gem install pg -- --with-pg-config=<path to pg_config>

If you're installing via Bundler, you can provide compile hints like so:

bundle config --with-pg-config=<path to pg_config>

See README-OS_X.rdoc for more information about installing under MacOS X, and README-Windows.rdoc for Windows build/installation instructions.

There's also a Google+ group and a mailing list if you get stuck, or just want to chat about something.


To report bugs, suggest features, or check out the source with Mercurial, check out the project page. If you prefer Git, there's also a Github mirror.

After checking out the source, run:

$ rake newb

This task will install any missing dependencies, run the tests/specs, and generate the API documentation.

The current maintainers are Michael Granger <> and Lars Kanis <>.


Copyright © 1997-2013 by the authors.

  • Jeff Davis <>

  • Guy Decoux (ts) <>

  • Michael Granger <>

  • Lars Kanis <>

  • Dave Lee

  • Eiji Matsumoto <>

  • Yukihiro Matsumoto <>

  • Noboru Saitou <>

You may redistribute this software under the same terms as Ruby itself; see or the LICENSE file in the source for details.

Portions of the code are from the PostgreSQL project, and are distributed under the terms of the PostgreSQL license, included in the file POSTGRES.

Portions copyright LAIKA, Inc.


See Contributors.rdoc for the many additional fine people that have contributed to this library over the years.

We are thankful to the people at the ruby-list and ruby-dev mailing lists. And to the people who developed PostgreSQL.

Something went wrong with that request. Please try again.