Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Configuring a Data Source in the Linux OS

Updated on 2025-02-27 GMT+08:00

Before using ODBC to connect to a database, you need to prepare the required resources. To connect to a database, you need to configure the ODBC data source or use the ODBC APIs or the driver to implement the communication and interaction between an application and a database. This section describes how to configure a data source and connect to a database in the Linux OS.

Procedure

  1. Install unixODBC. (By default, the unixODBC source code package has been obtained during environment preparation.) It does not matter if unixODBC of another version has been installed.

    For example, to install unixODBC-2.3.7, run the commands below.
    tar zxvf unixODBC-2.3.7.tar.gz
    cd unixODBC-2.3.7
    
    ./configure --enable-gui=no # To perform compilation on an Arm server, add the configure parameter --build=aarch64-unknown-linux-gnu.
    make
    # The installation may require root permissions.
    make install
    NOTE:
    • Currently, unixODBC-2.2.1 is not supported.
    • By default, it is installed in the /usr/local directory. The data source file is generated in the /usr/local/etc directory, and the library file is generated in the /usr/local/lib directory.
    • You can compile unixODBC with the --enable-fastvalidate=yes option to achieve higher performance. However, this option may cause an application that passes an invalid handle to the ODBC API to fail instead of returning an SQL_INVALID_HANDLE error.

  2. Replace the GaussDB client driver.

    Decompress GaussDB-Kernel-Database version number-OS version number-64bit-Odbc.tar.gz. After the decompression, the lib and odbc folders are generated. The odbc folder contains another lib folder. Copy all dynamic libraries in the /lib and /odbc/lib folders to the /usr/local/lib directory.

  3. Configure a data source.

    1. Configure the ODBC driver file.

      Add the following content to the /usr/local/etc/odbcinst.ini file:

      [GaussMPP]
      Driver64=/usr/local/lib/psqlodbcw.so
      setup=/usr/local/lib/psqlodbcw.so

      For descriptions of the parameters in the odbcinst.ini file, see Table 1.

      Table 1 odbcinst.ini configuration parameters

      Parameter

      Description

      Example

      [DriverName]

      Driver name, corresponding to Driver in DSN.

      [GaussMPP]

      Driver64

      Path of the dynamic driver library.

      Driver64=/usr/local/lib/psqlodbcw.so

      setup

      Driver installation path, which is the same as the dynamic library path in Driver64.

      setup=/usr/local/lib/psqlodbcw.so

    2. Configure the data source file.

      Add the following content to the /usr/local/etc/odbc.ini file:

      [gaussdb]
      Driver=GaussMPP
      Servername=127.0.0.1 # Database server IP address
      Database=postgres  # Database name
      Username=omm  # Database username
      Password=  # Database user password
      Port=8000  # Database listening port
      Sslmode = allow

      For descriptions of the parameters in the odbc.ini file, see Table 2.

      Table 2 odbc.ini configuration parameters

      Parameter

      Description

      Example

      [DSN]

      Data source name.

      [gaussdb]

      Driver

      Driver name, corresponding to DriverName in odbcinst.ini.

      Driver=GaussMPP

      Servername

      Server IP address. Multiple IP addresses can be configured.

      Servername=127.0.0.1

      Database

      Name of the database to connect to.

      Database = postgres

      Username

      Database username.

      Username = omm

      Password

      Database user password.

      NOTE:

      After a user establishes a connection, the ODBC driver automatically clears their password stored in memory.

      However, if this parameter is configured, UnixODBC will cache data source files, which may cause the password to be stored in the memory for a long time.

      When you connect to an application, you are advised to send your password through an API instead of writing it in a data source configuration file. After the connection has been established, immediately clear the memory segment where your password is stored.

      NOTICE:
      The password in the configuration file must comply with the following HTTP rules:
      1. Characters must comply with the URL encoding specifications. For example, the exclamation mark (!) must be written as %21, and the percent sign (%) must be written as %25. Therefore, pay attention to the handling of the percent sign (%).
      2. A plus sign (+) will be replaced by a space.

      Password=********

      Port

      Port number of the server.

      Port = 8000

      Sslmode

      Specifies whether to enable SSL.

      NOTE:

      For details about the values of the Sslmode option, see Table 3.

      Sslmode = allow

      Debug

      Specifies whether to enable the debugging mode.

      Value range: 0 to INT_MAX.

      • If this parameter is set to 0, the function is disabled.
      • If this parameter is set to a value greater than 0, the mylog file of the psqlodbc driver will be printed. The directory generated for storing logs is /tmp/.

      The default value is 0.

      Debug = 1

      UseServerSidePrepare

      Specifies whether to enable the extended query protocol for the database.

      Value range: 0 and 1

      • If this parameter is set to 0, the function is disabled.
      • If this parameter is set to 1, the function is enabled.

      The default value is 1.

      UseServerSidePrepare = 1

      UseBatchProtocol

      Specifies whether to enable the batch query protocol. If it is enabled, DML performance can be improved.

      Value range: 0 and 1

      • If this parameter is set to 0, the batch query protocol is disabled (mainly for communication with earlier database versions).
      • If this parameter is set to 1 and support_batch_bind is set to on, the batch query protocol is enabled.

      The default value is 1.

      UseBatchProtocol = 1

      ForExtensionConnector

      Specifies whether the savepoint is sent.

      Value range: 0 and 1

      • If this parameter is set to 0, the savepoint is sent.
      • If this parameter is set to 1, the savepoint is not sent.

      The default value is 1.

      ForExtensionConnector = 1

      ConnectionExtraInfo

      Specifies whether to display the driver deployment path and process owner in the connection_info GUC parameter.

      Value range: 0 and 1

      • If this parameter is set to 0, the information is not displayed.
      • If this parameter is set to 1, the information is displayed.

      The default value is 0.

      NOTE:

      The default value is 0. If this parameter is set to 1, the ODBC driver reports the driver deployment path and process owner to the database and displays the information in the connection_info parameter. In this case, you can query the information from PG_STAT_ACTIVITY.

      ConnectionExtraInfo = 1

      BoolAsChar

      Specifies whether to process Boolean values as characters.

      Value range: 0 and 1

      • If this parameter is set to 0, the Boolean values are mapped to the SQL_BIT type.
      • If this parameter is set to 1, the Boolean values are mapped to the SQL_CHAR type.

      The default value is 1.

      BoolsAsChar = 1

      RowVersioning

      Specifies whether to allow the application to check whether a row of data is modified by another user when the row of data is updated.

      Value range: 0 and 1

      • If this parameter is set to 0, application detection is not allowed.
      • If this parameter is set to 1, application detection is allowed.

      The default value is 0.

      RowVersioning=1

      ShowSystemTables

      Specifies whether to regard the system catalog as a common SQL table by default.

      Value range: 0 and 1

      • If this parameter is set to 0, the driver does not regard the system catalog as a common SQL table by default.
      • If this parameter is set to 1, the driver regards the system catalog as a common SQL table by default.

      The default value is 0.

      ShowSystemTables=1

      TcpUserTimeout

      Specifies the maximum duration for which transmitted data can remain unacknowledged before the TCP connection is forcibly closed on an OS that supports the TCP_USER_TIMEOUT socket option.

      Value range: 0 to INT_MAX.

      The default value is 0.

      NOTE:

      0 indicates that the default value is used. Ignore this parameter for UDS connections. The unit is millisecond.

      TcpUserTimeout=5000

      The valid values of Sslmode are as follows:

      Table 3 Sslmode options

      Sslmode

      Whether SSL Encryption Is Enabled

      Description

      disable

      No

      SSL connection is not enabled.

      allow

      Possible

      If the database server requires SSL connection, SSL connection can be enabled. However, authenticity of the database server will not be verified.

      prefer

      Possible

      If the database supports SSL connection, SSL connection is recommended. However, authenticity of the database server will not be verified.

      require

      Yes

      SSL connection is required and data is encrypted. However, authenticity of the database server will not be verified.

      verify-ca

      Yes

      SSL connection is required and whether the database has a trusted certificate will be verified.

      verify-full

      Yes

      SSL connection is required. In addition to the check scope specified by verify-ca, the system checks whether the name of the host where the database resides is the same as that in the certificate. GaussDB does not support this mode.

      NOTE:

      When establishing connections to the GaussDB server using ODBC, you can enable SSL connections to encrypt client and server communications. To enable SSL connection, you must have the server certificate, client certificate, and private key files. For details on how to obtain these files, see related documents and commands of OpenSSL.

  4. Configure the environment variables on the client.

    vim ~/.bashrc

    Add the following information to the configuration file:

    export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
    export ODBCSYSINI=/usr/local/etc
    export ODBCINI=/usr/local/etc/odbc.ini

  5. Run the following command to validate the addition:

    source ~/.bashrc

  6. Test the connection.

    After the installation, the generated binary file is stored in the /usr/bin directory. You can run the isql -v gaussdb command (gaussdb is the data source name).

    • If the following information is displayed, the configuration is correct and the connection succeeds:
      +---------------------------------------+
      | Connected!                            |
      |                                       |
      | sql-statement                         |
      | help [tablename]                      |
      | quit                                  |
      |                                       |
      +---------------------------------------+
    • If error information is displayed, the configuration is incorrect. Check whether the preceding configuration steps are correctly performed.
    NOTE:
    When the ODBC is used to connect to a database, the kernel parameters are set as follows:
    SET extra_float_digits = 2;
    SET DateStyle = 'ISO';

    These parameters may cause the ODBC and gsql clients to display inconsistent data, for example, date data display mode and floating-point precision representation. If the result is not as expected, you are advised to explicitly set these parameters in the ODBC application code.

FAQ

  • [UnixODBC][Driver Manager]Can't open lib 'xxx/xxx/psqlodbcw.so' : file not found.

    Possible causes:

    • The path configured in the odbcinst.ini file is incorrect.

      Run ls to check the path in the error information, ensuring that the psqlodbcw.so file exists and you have execution permissions on it.

    • The dependent library of psqlodbcw.so does not exist or is not in system environment variables.

      Run ldd to check the path in the error information. If libodbc.so.1 or other unixODBC libraries do not exist, configure unixODBC again following the procedure provided in this section, and add the lib directory under its installation directory to LD_LIBRARY_PATH. If other libraries do not exist, add the lib directory under the ODBC driver package to LD_LIBRARY_PATH. If other standard libraries are missing, install them.

  • [UnixODBC]connect to server failed: no such file or directory

    Possible causes:

    • An incorrect or unreachable database IP address or port was configured.

      Check the Servername and Port configuration items in data sources.

    • Server monitoring is improper.

      If Servername and Port are correctly configured, ensure the proper network adapter and port are monitored by following the database server configurations in the procedure in this section.

    • Firewall and network gatekeeper settings are improper.

      Check firewall settings, and ensure that the database communication port is trusted.

      Check to ensure network gatekeeper settings are proper (if any).

  • [unixODBC]The password-stored method is not supported.

    Possible causes:

    The sslmode configuration item is not configured in the data sources.

    Solution:

    Set the configuration item to allow or a higher level. For details, see Table 3.

  • Server common name "xxxx" does not match host name "xxxxx"

    Possible causes:

    When verify-full is used for SSL encryption, the driver checks whether the host name in certificates is the same as the actual one.

    Solution:

    To solve this problem, use verify-ca to stop checking host names, or generate a set of CA certificates containing the actual host names.

  • Driver's SQLAllocHandle on SQL_HANDLE_DBC failed

    Possible causes:

    The executable file (such as the isql tool of unixODBC) and the database driver (psqlodbcw.so) depend on different library versions of ODBC, such as libodbc.so.1 and libodbc.so.2. You can verify this problem by using the following method:

    ldd `which isql` | grep odbc
    ldd psqlodbcw.so | grep odbc

    If the suffix digits of the outputs libodbc.so are different or indicate different physical disk files, this problem exists. Both isql and psqlodbcw.so load libodbc.so. If different physical files are loaded, different unixODBC libraries with the same function list conflict with each other in a visible domain. As a result, the database driver cannot be loaded.

    Solution:

    Uninstall the unnecessary unixODBC, such as libodbc.so.2, and create a soft link with the same name and the .so.2 suffix for the remaining libodbc.so.1 library.

  • FATAL: Forbid remote connection with trust method!

    For security purposes, the primary database node forbids access from other nodes in the database without authentication.

    To access the primary database node from inside the database, deploy the ODBC program on the host where the primary database node is located and set the server address to 127.0.0.1. It is recommended that the service system be deployed outside the database. Otherwise, the database performance may be affected.

  • [unixODBC][Driver Manager]Invalid attribute value

    The unixODBC version may not be the recommended one. You are advised to run the odbcinst --version command to check the unixODBC version in the environment.

  • authentication method 10 not supported.

    If this error occurs on an open-source client, the cause may be:

    The database stores only the SHA-256 hash of the password, but the open-source client supports only MD5 hashes.

    NOTE:
    • The database stores the hashes of user passwords instead of actual passwords.
    • If a password is updated or a user is created, both types of hashes will be stored, compatible with open-source authentication protocols.
    • An MD5 hash can only be generated using the original password, but the password cannot be obtained by reversing its SHA-256 hash. Passwords in the source version will only have SHA-256 hashes and not support MD5 authentication.
    • The MD5 encryption algorithm has lower security and poses security risks. Therefore, you are advised to use a more secure encryption algorithm.

    To solve this problem, you can update the user password (see ALTER USER) or create a user (see CREATE USER) having the same permissions as the faulty user.

  • unsupported frontend protocol 3.51: server supports 1.0 to 3.0

    The database version is too early or the database is an open-source database.

    Use the driver of the required version to connect to the database.

  • FATAL: GSS authentication method is not allowed because XXXX user password is not disabled.

    In pg_hba.conf of the target primary database node, the authentication mode is set to gss for authenticating the IP address of the current client. However, this authentication algorithm cannot authenticate clients. Change the authentication algorithm to sha256 and try again.

  • isql: error while loading shared libraries:xxx

    The dynamic library does not exist in the environment. You need to install the corresponding library.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback