Client drivers for YSQL

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.

Yugabyte and third party 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

C#

Npgsql YugabyteDB Smart Driver

The YugabyteDB Npgsql Smart Driver is a .NET driver for YSQL built on the PostgreSQL Npgsql driver, with features that eliminate the need for external load balancers.

For information on the YugabyteDB Npgsql Smart Driver and its load balancing features, see YugabyteDB Npgsql Smart Driver.

For building a sample C# application with the YugabyteDB Npgsql driver, see Connect an application.

Npgsql

Npgsql is an open source ADO.NET Data Provider for PostgreSQL that enables C# applications to connect and interact with PostgreSQL databases. Npgsql is based on libpq and supports the SCRAM-SHA-256 authentication method.

For details on Npgsql, refer to the Npgsql documentation.

For building a sample C# application with Npgsql, see Connect an application.

Install the driver

To include Npgsql in your application, add the following package reference to your .cproj file.

<PackageReference Include="npgsql" Version="6.0.3" />

If you are using Visual Studio, add Npgsql to your project as follows:

  1. Open the Project Solution View.

  2. Right-click on Packages and click Add Packages.

  3. Search for Npgsql and click Add Package.

Warning

On every new connection the NpgSQL driver also makes extra system table queries to map types, which adds significant overhead. To turn off this behavior, set the following option in your connection string builder:

connStringBuilder.ServerCompatibilityMode = ServerCompatibilityMode.NoTypeLoading;

Go

YugabyteDB PGX Smart Driver

The YugabyteDB PGX smart driver is a distributed Go driver for YSQL based on jackc/pgx, with a additional connection load balancing features.

For information on the YugabyteDB PGX smart driver and its load balancing features, see YugabyteDB PGX smart driver.

For building a sample Go application with the YugabyteDB PGX driver, see Connect an application.

Go PostgreSQL driver (pq)

The Go PostgreSQL driver package (pq) is a Go PostgreSQL driver for the database/sql package. pq is not based on libpq, but supports the SCRAM-SHA-256 authentication method.

For a tutorial on building a sample Go application with pq, see Connect an application.

Install the pq driver

To install the package locally, run the following go get command:

$ go get github.com/lib/pq

The pq driver is ready for building Go applications that connect to and interact with YugabyteDB.

Java

YugabyteDB JDBC Smart Driver

The YugabyteDB JDBC Smart Driver is a distributed JDBC driver for YSQL built on the PostgreSQL JDBC driver, with features that eliminate the need for external load balancers.

For information on the YugabyteDB JDBC Smart Driver and its load balancing features, see YugabyteDB JDBC Smart Driver.

For building a sample Java application with the YugabyteDB JDBC driver, see Connect an application.

PostgreSQL JDBC driver (PgJDBC)

The PostgreSQL JDBC driver is the official JDBC driver for PostgreSQL. PgJDBC is not based on libpq, but supports the SCRAM-SHA-256 authentication method.

For building a sample Java application with the PostgreSQL JDBC driver, see Connect an application.

Install the PostgreSQL JDBC driver

To download binary JAR files, go to PostgreSQL JDBC driver – Downloads. Because Java is platform neutral, download the appropriate JAR file and drop it into the classpath.

To get the latest versions for projects using Apache Maven, see Maven Central Repository Search.

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.

Node.js

YugabyteDB node-postgres Smart Driver

The YugabyteDB node-postgres Smart Driver is a distributed Node.js driver for YSQL built on the PostgreSQL node-postgres driver, with features that eliminate the need for external load balancers.

For information on the YugabyteDB node-postgres Smart Driver and its load balancing features, see YugabyteDB node-postgres Smart Driver.

For building a sample node.js application with the YugabyteDB node-postgres driver, see Connect an application.

node-postgres

node-postgres is a collection of Node.js modules for interacting with PostgreSQL databases. node-postgres optionally uses libpq and supports the SCRAM-SHA-256 authentication method.

For details on installing and using node-postgres, see the node-postgres documentation.

For a tutorial on building a Node.js application with node-postgres, see Connect an application.

Install the node-postgres (pg) driver

To install node-postgres and any packages it depends on, run the following npm install command:

$ npm install pg

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

YugabyteDB Psycopg2 Smart Driver

The YugabyteDB Psycopg2 Smart Driver is a distributed Node.js driver for YSQL built on the PostgreSQL Psycopg2 driver, with features that eliminate the need for external load balancers.

For information on the YugabyteDB Psycopg2 Smart Driver and its load balancing features, see YugabyteDB Psycopg2 Smart Driver.

For building a sample Python application with the YugabyteDB Psycopg2 driver, see Connect an application.

psycopg2

Psycopg is the popular PostgreSQL database adapter for the Python programming language. psycopg2 is based on libpq and supports the SCRAM-SHA-256 authentication method.

For details on using psycopg2, see Psycopg documentation.

For a tutorial on building a sample Python application that uses psycopg2, see Connect an application.

Install the psycopg2 binary

To install the psycopg2 binary package, run the following pip3 install command:

$ pip3 install psycopg2-binary

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"