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, see What Features Does YSQL 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.
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 Build a C 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.
For a tutorial on building a sample C++ application with libpqxx, refer to Build a C++ 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
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.
To follow a tutorial on building a sample C# application with Npgsql, see Build a C# application.
Install the driver
To include Npgsql in your application, add the following package reference to your
<PackageReference Include="npgsql" Version="6.0.3" />
If you are using Visual Studio, add Npgsql to your project as follows:
Open the Project Solution View.
Right-click on Packages and click Add Packages.
Search for Npgsql and click Add Package.
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 PostgreSQL driver (pq)
For a tutorial on building a sample Go application with pq, see Build a Go 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.
Yugabyte JDBC driver
The Yugabyte JDBC 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 Yugabyte JDBC driver and its load balancing features, see Yugabyte JDBC driver.
For a tutorial on building a sample Java application with the Yugabyte JDBC driver, see Build a Java application.
PostgreSQL JDBC driver (PgJDBC)
For a tutorial on building a sample Java application with the PostgreSQL JDBC Driver, see Build a Java 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.
For details on installing and using node-postgres, see the node-postgres documentation.
For a tutorial on building a sample Node.js application with node-postgres, see Build a Node.js 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
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 Build a PHP 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.
For details on using psycopg2, see Psycopg documentation.
For a tutorial on building a sample Python application that uses psycopg2, see Build a Python application.
Install the psycopg2 binary
To install the psycopg2 binary package, run the following
pip3 install command:
$ pip3 install psycopg2-binary
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 Build a Python application.
To install the aiopg package, run the following
pip3 install command:
pip3 install aiopg
For a tutorial on building a sample Ruby application with pg, see Build a Ruby 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
<path-to-libpq> with the path to the libpq installation; for example,
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
postgres = "0.19.2" openssl = "0.10.38" postgres-openssl = "0.5.0"