Ready to get started?

Download a free trial of the SingleStore ODBC Driver to get started:

 Download Now

Learn more:

SingleStore Icon SingleStore ODBC Driver

The SingleStore ODBC Driver is a powerful tool that allows you to connect with live data from SingleStore, directly from any applications that support ODBC connectivity.

Access SingleStore data like you would a database - read, write, and update SingleStore. through a standard ODBC Driver interface.

A PostgreSQL Interface for SingleStore Data



Use the SQL Gateway and SingleStore ODBC Driver to create a PostgreSQL entry-point for data access.

There are a vast number of PostgreSQL clients available on the Internet. From standard Drivers to BI and Analytics tools, PostgreSQL is a popular interface for data access. Using the SQL Gateway included in our ODBC Drivers, you can now create PostgreSQL entry-points that you can connect to from any standard client.

To access SingleStore data as a PostgreSQL database on Windows, use the CData SQL Gateway, the ODBC Driver for SingleStore, and the MySQL foreign data wrapper from EnterpriseDB. In this article, we compile the foreign data wrapper in Visual Studio, install it as an extension, and query SingleStore data from PostgreSQL Server.

Configure the Connection to SingleStore

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

The following connection properties are required in order to connect to data.

  • Server: The host name or IP of the server hosting the SingleStore database.
  • Port: The port of the server hosting the SingleStore database.
  • Database (Optional): The default database to connect to when connecting to the SingleStore Server. If this is not set, tables from all databases will be returned.

Connect Using Standard Authentication

To authenticate using standard authentication, set the following:

  • User: The user which will be used to authenticate with the SingleStore server.
  • Password: The password which will be used to authenticate with the SingleStore server.

Connect Using Integrated Security

As an alternative to providing the standard username and password, you can set IntegratedSecurity to True to authenticate trusted users to the server via Windows Authentication.

Connect Using SSL Authentication

You can leverage SSL authentication to connect to SingleStore data via a secure session. Configure the following connection properties to connect to data:

  • SSLClientCert: Set this to the name of the certificate store for the client certificate. Used in the case of 2-way SSL, where truststore and keystore are kept on both the client and server machines.
  • SSLClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
  • SSLClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
  • SSLClientCertType: The certificate type of the client store.
  • SSLServerCert: The certificate to be accepted from the server.

Connect Using SSH Authentication

Using SSH, you can securely login to a remote machine. To access SingleStore data via SSH, configure the following connection properties:

  • SSHClientCert: Set this to the name of the certificate store for the client certificate.
  • SSHClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
  • SSHClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
  • SSHClientCertType: The certificate type of the client store.
  • SSHPassword: The password that you use to authenticate with the SSH server.
  • SSHPort: The port used for SSH operations.
  • SSHServer: The SSH authentication server you are trying to authenticate against.
  • SSHServerFingerPrint: The SSH Server fingerprint used for verification of the host you are connecting to.
  • SSHUser: Set this to the username that you use to authenticate with the SSH server.

Start the Remoting Service

The MySQL remoting service is a daemon process that listens for clients' incoming MySQL connections. See the setup guide in the SQL Gateway overview to configure the MySQL Remoting service in the CData SQL Gateway.

Build the MySQL Foreign Data Wrapper

The Foreign Data Wrapper can be installed as an extension to PostgreSQL, without recompiling PostgreSQL. If you are running PostgreSQL on a Unix-based system, you can use the PostgreSQL Extension Network (PGXN) to install the FDW, mysql_fdw. If you are running PostgreSQL on Windows, compile the extension to ensure that you are working with the latest version. Follow the steps below to make the necessary modifications to build the extension from Visual Studio:

Obtain Prerequisites

To build the foreign data wrapper, do the following:

  • Install PostgreSQL. This example uses an installation of PostgreSQL 9.4.
  • If you are using a 64-bit installation of PostgreSQL, obtain libintl.h from the PostgreSQL source. The 64-bit PostgreSQL installer does not currently include libintl.h.
  • Obtain the source for the mysql_fdw foreign data wrapper from EnterpriseDB.
  • Install MySQL Connector C. This example uses an installation of MySQL Connector C 6.1.

Configure a Project

After you have obtained the necessary software and source code, you are ready to compile the extension with Visual Studio. Follow the steps below to create a project using the mysql_fdw source:

  1. In Visual Studio, create a new empty C++ project.
  2. In Solution Explorer, right-click Source Files and click Add -> Existing Item. In the file explorer, select all of the .c and .h files from the mysql_fdw source.

Follow the steps below to configure your project:

  1. If you are building for a 64-bit system, click Build -> Configuration Manager and in Active Solution Platform select x64.
  2. Right-click your project and click Properties.
  3. In the Configuration menu, select All Configurations.
  4. In Configuration Properties -> General -> Configuration Type, select Dynamic Library.
  5. In Configuration Properties -> C/C++ -> Code Generation -> Enable C++ Exceptions, select No.
  6. In Configuration Properties -> C/C++ -> Advanced -> Compile As, select Compile as C Code.
  7. In Linker -> Manifest File -> Generate Manifest, select No.

Follow the steps below to add the required dependencies:

  1. In Linker -> Input -> Additional Dependencies, select Edit and enter the following: postgres.lib libmysql.lib WS2_32.lib Secur32.lib Additionally, ensure that Inherit From Parent or Project Defaults is checked.
  2. In Linker -> General -> Additional Library Directories, select Edit and add the path to the lib folder in your PostgreSQL installation.
  3. In Linker -> General -> Link Library Dependencies, select No.
  4. To complete the configuration of your project, add the necessary includes: In C/C++ -> General -> Additional Include Directories, add the following folders in the following order: MyMySQLConnectorCInstallation\include MyPostgreSQLInstallation\MyPostgreSQLVersion\include\server\port\win32_msvc MyPostgreSQLInstallation\MyPostgreSQLVersion\include\server\port\win32 MyPostgreSQLInstallation\MyPostgreSQLVersion\include\server MyPostgreSQLInstallation\MyPostgreSQLVersion\include

Configure mysql_fdw for Windows

After setting up a project, make the following changes to build mysql_fdw in Visual Studio:

  1. In mysql_fdw.c, add the following defines: #define dlsym(lib, name) (void*)GetProcAddress((HMODULE)lib, name) #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0)
  2. In the mysql_load_library definition, delete the following line: mysql_dll_handle = dlopen(_MYSQL_LIBNAME, RTLD_LAZY | RTLD_DEEPBIND);
  3. Add the following line in the mysql_load_library definition to replace the assignment of mysql_dll_handle for a Windows build: mysql_dll_handle = dlopen("libmysql.dll", 0);
  4. Prepend the call to the mysql_fdw_handler function with the __declspec(dllexport) keyword to export the function from the DLL: __declspec(dllexport) extern Datum mysql_fdw_handler(PG_FUNCTION_ARGS);
  5. In option.c, prepend the declaration of the mysql_fdw_validator function with the __declspec(dllexport) keyword to export the function from the DLL: __declspec(dllexport) extern Datum mysql_fdw_validator(PG_FUNCTION_ARGS);

You can now select the Release configuration and build.

Install the Extension

After you have compiled the DLL, follow the steps below to install the extension:

  1. Add the path to the lib folder for MySQL Connector C to the PATH environment variable of the machine running PostgreSQL.
  2. Copy the DLL from the RElease folder for your project into the lib subfolder of your PostgreSQL installation.
  3. In the folder containing the mysql_fdw csource files, copy myswl_fdw--1.0.sql and mysql_fdw.control into the extension folder under the share folder of your PostgreSQL installation. For example: C:\Program Files\PostgreSQL\9.4\share\extension.

Query SingleStore Data as a PostgreSQL Database

After you have installed the extension, follow the steps below to start executing queries to SingleStore data:

  1. Log into your PostgreSQL database. For example: C:\> psql -U postgres
  2. Load the extension for the database: postgres=#CREATE EXTENSION mysql_fdw;
  3. Create a server object for SingleStore data: postgres=# CREATE SERVER SingleStore FOREIGN DATA WRAPPER mysql_fdw OPTIONS (host '127.0.0.1', port '3306');
  4. Create a user mapping for the username and password of a user known to the MySQL remoting service. Below are the credentials for the user in the sample configuration of the service: postgres=# CREATE USER MAPPING for postgres SERVER SingleStore OPTIONS (username 'admin', password 'test');
  5. Create the local schema: postgres=# CREATE SCHEMA SingleStore_db;
  6. Import all the tables in the SingleStore database you defined: postgres=# IMPORT FOREIGN SCHEMA "CData SingleStore Sys" FROM SERVER SingleStore INTO SingleStore_db;

You can now execute read/write commands to SingleStore:

postgres=# SELECT * FROM SingleStore_db."orders";