A PostgreSQL client library for Ruby providing a native interface with advanced type casting and modern Ruby concurrency support.
Pg is a PostgreSQL client library for Ruby that provides a native interface to connect and interact with PostgreSQL databases. It solves the problem of efficient and full-featured database communication by offering direct bindings to libpq, advanced type casting, and support for modern Ruby concurrency models.
Ruby developers building applications that require PostgreSQL database connectivity, especially those needing performance, custom type handling, or working with concurrent Ruby features like Fibers and Ractors.
Developers choose Pg for its mature, high-performance native bindings, comprehensive type casting system, and first-class support for Ruby's latest concurrency features, making it the most capable PostgreSQL adapter for Ruby.
A PostgreSQL client library for Ruby
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Direct Ruby bindings to libpq ensure efficient communication with PostgreSQL servers, as highlighted in the key features for high performance.
Customizable type encoders and decoders support both text and binary formats, allowing fine-grained control over data conversion, detailed in the type casts section.
Fully compatible with Ruby's Fiber scheduler since pg-1.3.0 and Ractor since pg-1.5.0, enabling safe concurrent programming without thread safety issues.
Pre-built gems with embedded libpq simplify setup on many platforms, reducing system dependency headaches, as noted in the installation instructions.
Flexible type maps like TypeMapByOid and TypeMapByClass provide detailed control over encoding and decoding strategies, supporting complex data handling.
Binary gems do not support retrieval of connection options from LDAP due to missing libldap, forcing use of source gems in such cases.
Advanced type casting requires manual configuration of type maps and coders, which can be overwhelming for simple queries or beginners.
Methods for large objects and certain authentication operations are not fully compatible with Fiber scheduler, potentially causing blocking in concurrent environments.
On platforms like Alpine Linux, binary gems may require additional packages (e.g., gcompat), and source gems need pg_config, adding setup complexity.