ODBC

Updated at:
Copy as MD

Connect client applications to PolarDB for PostgreSQL (Compatible with Oracle) using the Open Database Connectivity (ODBC) driver on Windows or Linux/Unix.

Prerequisites

Before you begin, make sure that you have:

  • A PolarDB cluster with a database account created

  • The client IP address added to the cluster whitelist

  • A supported operating system:

    • Windows: Windows 7 or later with Service Pack 1

    • Linux/Unix: Libtool 1.5.10 or later and unixODBC-devel installed

Download the driver

Select the package that matches your operating system and processor architecture.

Operating system Architecture Driver package
AliOS 8, ALinux 3, Anolis 8, or CentOS 8 X86_64 polardb-odbc-x86_64-8u-13.02.0000.1.tar.gz
ARM_64 polardb-odbc-aarch64-8u-13.02.0000.1.tar.gz
AliOS 2, ALinux 2, Anolis 7, or CentOS 7 X86_64 polardb-odbc-x86_64-7u-13.02.0000.1.tar.gz
ARM_64 polardb-odbc-aarch64-7u-13.02.0000.1.tar.gz
Unix/Linux 6 X86_32 polardb-odbc-X86_32-6u-13.02.0000.1.tar.gz
Ubuntu 18 X86_64 polardb-odbc-x86_64-ubuntu18.04-13.02.0000.1.tar.gz
Windows 7 or later X86_64 polardb2_odbc_x64_13.02.0000.1.msi
X86_32 polardb2_odbc_x86_13.02.0000.1.msi

Use the ODBC driver on Windows

Install the driver

  1. Download the .msi package that matches your Windows architecture. See Download the driver.

  2. Right-click the polardb2_odbc_*_*.msi file and select Run as administrator to install the driver.

Connect to PolarDB

  1. Open Control Panel > Administrative Tools > ODBC Data Sources.

  2. In the ODBC Data Source Administrator dialog box, click Add.

  3. Select PolarDB Unicode(x64) and click Finish.

  4. Fill in the connection details:

    image.png

    Parameter Description Default
    Data Source A name for this data source.
    Description An optional description of the data source.
    Database The name of the destination database.
    SSL Mode The SSL encryption mode.
    Server The cluster endpoint. To find it, see View or request an endpoint.
    Port The database port. 1521
    User Name The database account.
    Password The password for the database account.
  5. Click Test to verify the connection. A success message confirms that the connection string is correctly configured.

    image.png

  6. Click Save.

Use the ODBC driver on Linux or Unix

Note

The following steps use CentOS as an example. Commands may differ depending on your distribution.

Install the driver

  1. Download the driver package that matches your operating system and architecture. See Download the driver.

  2. Extract the package. The PolarDB ODBC driver does not require installation — it's ready to use after extraction.

    tar -zxvf polardb-odbc-*-*-*.tar.gz

    Replace polardb-odbc-*-*-*.tar.gz with the actual package name.

  3. Set the LD_LIBRARY_PATH environment variable to point to the driver library:

    export LD_LIBRARY_PATH=<PolarDB-ODBC/lib>:$LD_LIBRARY_PATH

    Replace <PolarDB-ODBC/lib> with the actual path to the extracted lib folder.

  4. Set the ODBCINI environment variable to point to your odbc.ini file:

    export ODBCINI=</your/odbc.ini/file/path>

Connect to PolarDB

  1. Install Libtool (1.5.1 or later) on the Linux server:

    yum install -y libtool
  2. Install unixODBC-devel:

    yum install -y unixODBC-devel
  3. Open the odbc.ini file configured in ODBCINI:

    vim $ODBCINI
  4. Add the following data source definition:

    Field Description Default
    [POLARDB] The data source name. Use any name you like.
    Description An optional description of this data source.
    Driver / Driver64 The path to psqlodbcw.so in the extracted lib folder.
    Database The name of the destination database.
    Servername The cluster endpoint. To find it, see View or request an endpoint.
    Password The password for the database account.
    Port The database port.
    Username The database account.
    Trace Set to yes to enable unixODBC tracing, which logs all ODBC calls. Useful for troubleshooting; disable in production to avoid performance overhead. yes
    TraceFile The file where trace output is written. /tmp/odbc.log
    FileUsage Set to 1 to indicate this is a file-based data source. 1
    [POLARDB]
    Description = ODBC for POLARDB
    Driver      = <PolarDB-ODBC/lib/psqlodbcw.so>
    Driver64    = <PolarDB-ODBC/lib/psqlodbcw.so>
    Database    = <database_name>
    Servername  = <database_endpoint>
    Password    = <password>
    Port        = <port>
    Username    = <username>
    Trace       = yes
    TraceFile   = /tmp/odbc.log
    FileUsage   = 1

    Replace <PolarDB-ODBC/lib/> with the actual path to the extracted lib folder.

  5. Connect to PolarDB:

    $isql -v POLARDB

    Expected output:

    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL>

FAQ

When I use PowerBuilder to query data through ODBC, I get the error `ERROR: column "_polarHiddenprefix_dts_ROWID" does not exist` or `ERROR: column "polar_sys_rowid_attr" does not exist`.

This is a known issue with how earlier driver versions handle hidden columns. Upgrade to ODBC driver version 13.02.0000.1 or later to resolve it.

When I use PowerBuilder to run a query, I get the error `ERROR: syntax error at or near "limit"`.

This error occurs when an SQL reserved keyword is used as a column name. Upgrade to ODBC driver version 13.02.0000.1 or later to resolve it.

When I use isql to connect to PolarDB, I see `Can't open lib '/my/path/to/psqlodbcw.so' : file not found`, but the file exists.

The file exists, but a dynamic library it depends on — most likely libpq.so — is missing or not on the system path. Run ldd to check which dependencies are unresolved:

ldd /my/path/to/psqlodbcw.so

Look for entries marked not found in the output:

linux-vdso.so.1 =>  (0x00007ffd7916a000)
libpq.so.5 => not found
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f388ac00000)
libodbcinst.so.2 => /lib64/libodbcinst.so.2 (0x00007f388a800000)
libc.so.6 => /lib64/libc.so.6 (0x00007f388a400000)
/lib64/ld-linux-x86-64.so.2 (0x00007f388afd1000)
libltdl.so.7 => /lib64/libltdl.so.7 (0x00007f388a000000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f3889c00000)

Add the directory containing the missing library to LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=<path/to/library/directory>:$LD_LIBRARY_PATH

Update log

13.02.0000.1 (February 10, 2025)

  • Type compatibility

    • The DATE type is now compatible with Oracle and supports time information, including hours, minutes, and seconds.

    • The INTERVAL type is now compatible with Oracle. To query an INTERVAL column, convert it to a string first.

  • API adaptation

    • PGAPI_Columns and related APIs are updated for ROWID and DTS. System columns and system indexes are no longer displayed.

    • PGAPI_Columns now supports using SQL reserved keywords as column names.