Version 130 (modified by jtv, 8 years ago) (diff)


C++ connector for PostgreSQL

libpqxx is the official C++ client API for PostgreSQL, the enterprise-strength open-source relational database. (If "PostgreSQL" is too verbose, call it by its shorter name, postgres).

If you are writing software in C++ that needs to access databases managed by postgres—on just about any platform—then libpqxx is the library you use. It is the standard C++ language binding for the postgres RDBMS.

The source code for libpqxx is available under the BSD license, so you're free to download it, pass it on to others, change it, sell it, include it in your own code, and share your changes with anyone you choose. No charge, no catch. In most cases you'll want a pre-built package provided by a package maintainer for your platform, and distributed through your normal package management infrastructure.


2011-04-14: Declaring victory over site outages

Last month we identified and made a configuration change that our hosting provider required for the server's last operating system upgrade. We haven't had any outages since. Phew!

2011-03-28: We're retooling

After some intense back-and-forth with our hosting provider over the weekend, another potential source of our recurring site outages has been identified and fixed. Here's hoping!

Meanwhile, the script that implements the daily test runs is being rewritten. It's going to be a lot faster, but there will be some teething problems as we work on it. This may affect daily snapshot builds.

2011-03-28: gcc 4.6.0

A new gcc series was released on Friday. A few minor warnings in the libpqxx code have been fixed.

Finding Everything

Where What
Sales Pitch Why this library should interest you
Using This Site The various services offered by this development site
Download Page Source archives (no binaries; those depend on your individual platform)
FAQ Frequently Asked Questions, and their answers
Online Documentation Wiki and copies of packaged documentation
Packagers Page Information for maintainers of libpqxx packages
Consulting? Where can I get professional development help?
Bug Tracker Known bugs and requests (as in View Tickets option in top button bar)
Reporting Bugs How to report a problem or request a new feature
Mailing Lists Hosted on pgFoundry site
Database Notes Notes and tips about postgres
Performance Tips Figure out and solve performance problems
Other Projects Other open-source development projects hosted here
libpqxx Elsewhere Sites where libpqxx is registered as a project
Author and Contributors Who made all this?

For issues not suitable for the mailing list or bug tickets, contact the author as jtv at

Also, you may want to have a look at the other open source projects hosted on this site.

Technical Overview

This library works on top of the C-level API library, libpq. You will need libpq in order to use libpqxx.

The first thing you need to know is that libpqxx revolves around transactions. Transactions are a central concept in database management systems, but they are widely underappreciated among application developers. In libpqxx, they're fundamental.

With conventional database APIs, you issue commands and queries to a database session or connection, and optionally create the occasional transaction. In libpqxx you start with a connection, but you do all your SQL work in transactions that you open in your connection. You commit each transaction when it's complete; if you don't, all changes made inside the transaction get rolled back.

There are several types of transactions with various "quality of service" properties; if you don't really want to use transactions at all, one of the available transaction types is called nontransaction. This transaction type provides basic nontransactional behaviour.

Every command or query returns a result. All result data is fetched immediately. The result object is really a smart pointer so it can be copied around without incurring much cost in terms of performance. Don't check these for errors; failures show up as regular C++ exceptions. Result objects can be kept around for as long as they are needed, completely separate from the connections and transactions that originated them.

Ohloh Metrics GTF Contributor