Additional client drivers for YSQL YSQL
For production, use the latest stable version (v2024.1).
The Yugabyte Structured Query Language (YSQL) API builds upon and extends a fork of the query layer from PostgreSQL 11.2, with the intent of supporting most PostgreSQL functionality and adding new functionality to supported distributed SQL databases.
For details on PostgreSQL feature support in YSQL, refer to SQL feature support.
Client drivers listed below are supported for developing applications that connect to and interact with the YSQL API. Most of the drivers use libpq and support the SCRAM-SHA-256 authentication method.
For help using these drivers with YSQL, ask your questions in the Slack community.
If you encounter an issue or have an enhancement request, file a GitHub issue.
C
libpq
libpq is the C client library for connecting to and interacting with PostgreSQL databases. libpq is also the underlying engine used in other PostgreSQL application interfaces. The libpq client library supports the SCRAM-SHA-256 authentication method.
For details and documentation, refer to libpq - C Library for PostgreSQL 11 (on which YugabyteDB is based).
For a tutorial on building a sample C application with libpq, refer to Connect an application.
Install the libpq client library
The libpq C driver is included in the YugabyteDB installation. You can use it by setting the LD_LIBRARY_PATH
as follows:
$ export LD_LIBRARY_PATH=<yugabyte-install-dir>/postgres/lib
Homebrew users on macOS can install libpq using brew install libpq
. You can download the PostgreSQL binaries and source from the PostgreSQL Downloads page.
C++
libpqxx
The libpqxx driver is the official C++ client API for PostgreSQL. libpqxx is based on libpq and supports the SCRAM-SHA-256 authentication method.
For details and documentation, refer to the libpqxx README and libpqxx documentation.
For a tutorial on building a sample C++ application with libpqxx, refer to Connect an application.
Install the libpqxx driver
To build and install the libpqxx driver for use with YugabyteDB, first Clone the libpqxx repository.
$ git clone https://github.com/jtv/libpqxx.git
For dependencies on the PostgreSQL binaries, add the PostgreSQL bin
directory to the command path by running the following command.
$ export PATH=$PATH:<yugabyte-install-dir>/postgres/bin
Build and install the driver.
$ cd libpqxx
$ ./configure
$ make
$ make install
Java
Vert.x PG Client
Vert.x PG Client is the client for PostgreSQL with basic APIs to communicate with the database. It is a reactive and non-blocking client for handling the database connections with a single threaded API.
For a tutorial on building a sample Java application with the Vert.x PG Client, see Connect an application.
To get the latest versions for projects using Apache Maven, see Maven Central Repository of Vert.x PG Client.
PHP
php-pgsql
The php-pgsql driver is a collection of the official PostgreSQL module for PHP. php-pgsql is based on libpq and supports the SCRAM-SHA-256 authentication method.
For details on installing and using php-pgsql, see the php-pgsql documentation.
For a tutorial on building a sample PHP application with php-pgsql, see Connect an application.
Install the php-pgsql driver
To enable PostgreSQL support using php-pgsql, see Installing/Configuring in the PHP documentation.
Homebrew users on macOS can install PHP using brew install php
; the php-pgsql driver is installed automatically.
Ubuntu users can install the driver using the sudo apt-get install php-pgsql
command.
CentOS users can install the driver using the sudo yum install php-pgsql
command.
Python
aiopg
aiopg is a library for accessing a PostgreSQL database using the asyncio (PEP-3156/tulip) framework. It wraps asynchronous features of the Psycopg database driver. For details on using aiopg, see aiopg documentation.
For a tutorial on building a sample Python application that uses aiopg, see YSQL Aiopg.
Install
To install the aiopg package, run the following pip3 install
command:
pip3 install aiopg
Ruby
pg
pg is the Ruby interface for PostgreSQL databases. pg is based on libpq and supports the SCRAM-SHA-256 authentication method.
For a tutorial on building a sample Ruby application with pg, see Connect an application.
Install the pg driver
If you have installed YugabyteDB locally, run the following gem install command to install the pg driver:
$ gem install pg -- --with-pg-config=<yugabyte-install-dir>/postgres/bin/pg_config
Otherwise, to install pg, run the following command:
gem install pg -- --with-pg-include=<path-to-libpq>/libpq/include --with-pg-lib=<path-to-libpq>/libpq/lib
Replace <path-to-libpq>
with the path to the libpq installation; for example, /usr/local/opt
.
Rust
Rust-Postgres
Rust-Postgres is the Rust interface for PostgreSQL databases. Rust-Postgres is not based on libpq, but supports the SCRAM-SHA-256 authentication method.
For a tutorial on building a sample Ruby application with Rust-Postgres, see Build a Rust application.
Install the Rust-Postgres driver
To include the Rust-Postgres driver with your application, add the following dependencies to your cargo.toml
file:
postgres = "0.19.2"
openssl = "0.10.38"
postgres-openssl = "0.5.0"