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

Using gsql to Connect to a Database

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

gsql provided by GaussDB is a database connection tool running in the CLI. gsql provides basic and advanced functions of databases to facilitate user operations. This section describes how to use gsql to connect to a database. For details about how to use gsql, see "Client Tools > gsql" in Tool Reference.

Precautions

By default, when a client has been idle for the period specified by session_timeout after connecting to a database, the client automatically disconnects from the database. To disable the timeout setting, set session_timeout to 0.

Prerequisites

You have contacted the administrator for connection information.

Remotely Connecting to a Database

  1. Contact the administrator. to configure the remote connection.
  2. On the host, upload the client tool package and configure environment variables for the gsql client. The openEuler environment is used as an example.

    1. Log in to the client.
    2. Run the following command to create the /tmp/tools directory:
      mkdir /tmp/tools
    3. Obtain GaussDB-Kernel_VxxxRxxxCxx-XXXXX-64bit-gsql.tar.gz from the software installation package and upload it to the /tmp/tools directory.
      NOTE:
      • The software package is located where you put it before installation. Set it based on actual situation.
      • The tool package name may vary in different OSs. Select the tool package suitable for your OS.
    4. Run the following commands to decompress the package:
      cd /tmp/tools
      tar -zxvf GaussDB-Kernel_VxxxRxxxCxx-XXXXX-64bit-gsql.tar.gz
    5. Log in to the server where the primary database node is located, and copy the bin directory in the database installation directory to /tmp/tools on the client host.
      scp -r /opt/huawei/install/app/bin root@10.10.0.30:/tmp/tools

      In the preceding command, /opt/huawei/install/app indicates the {gaussdbAppPath} path configured in the clusterconfig.xml file, and 10.10.0.30 indicates the IP address of the client host.

    6. Log in to the host where the client is installed and set environment variables.

      Run the following command to open the ~/.bashrc file:

      vi ~/.bashrc

      Enter the following content and run :wq! to save and exit:

      export PATH=/tmp/tools/bin:$PATH
      export LD_LIBRARY_PATH=/tmp/tools/lib:$LD_LIBRARY_PATH
    7. Run the following command to make the environment variables take effect:
      source ~/.bashrc

  3. Connect to a database.

    After the database is installed, a database named postgres is generated by default. When connecting to a database for the first time, you can connect to this database.

    gsql -d postgres -h 10.10.0.11 -U jack -p 8000
    Password for user jack:

    postgres is the name of the database, 10.10.0.11 is the IP address of the server where the primary node of the database resides, jack is the user for connecting to the database, and 8000 is the port number of the primary database node.

    In a centralized database instance, when you need to connect to the primary node and the IP addresses of three nodes in the database instance are 10.10.0.11, 10.10.0.12, and 10.10.0.13, you can use the gsql -d postgres -h 10.10.0.11,10.10.0.12,10.10.0.13 -U jack -p 8000 command. gsql connects to the three IP addresses in sequence. If the current IP address is not the IP address of the primary node, gsql disconnects from the current IP address and attempts to connect to the next IP address, until the primary node is found.

    NOTE:
    • If a machine connected to GaussDB is not in the same network segment as GaussDB, the IP address specified by -h should be the value of coo.cooListenIp2 (application access IP address) set in Manager.
    • By default, the initial user of the database is not allowed to remotely connect to the database. If Kerberos authentication is enabled in an instance, the initial user is allowed to remotely connect to the database in the instance.

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