gsql is a database command-line connection tool provided by GaussDB(openGauss).
Currently, the gsql tool supports only the Euler OS.
To connect to a GaussDB(openGauss) DB instance through an ECS, you must first create an ECS running Euler OS. For details, see the Elastic Cloud Server User Guide.
mkdir /tmp/tools
The software package is located where you put it before installation.
cd /tmp/tools tar -zxvf GaussDB-Kernel-V500R001C00-EULER-64bit-gsql.tar.gz
vi ~/.bashrc
Enter the following content and run the :wq! command to save and then exit.
export PATH=/tmp/tools/bin:$PATH
export LD_LIBRARY_PATH=/tmp/tools/lib:$LD_LIBRARY_PATH
source ~/.bashrc
After the database is installed, a database named postgres is generated by default.
gsql -d postgres -h 10.0.0.0 -U jack -p 8000 Password for user jack:
postgres is the name of the database to be connected; 10.0.0.0 is the EIP bound to the DB instance; jack is the username for logging in to the database; 8000 is the port number of the DB instance.
Import the root certificate to the Linux OS on the ECS.
export PGSSLMODE=<sslmode> export PGSSLROOTCERT=<ca-file-directory>
gsql -h <host> -p <port> -d <database> -U <user> -W <password>
Parameter |
Description |
---|---|
<host> |
IP address of the DB instance. To obtain this parameter, go to the Basic Information page of the DB instance. If the DB instance is accessed through the ECS, the IP address can be found in the Floating IP Address field in the Connection Information area. |
<port> |
Database port in use. The default value is 8000. To obtain this parameter, go to the Basic Information page of the DB instance. The port number can be found in the Database Port field in the Connection Information area. |
<database> |
Name of the database (postgres by default). |
<user> |
Username of the database account. The default administrator is root. |
<ca-file-directory> |
Directory of the CA certificate for the SSL connection. The certificate should be stored in the directory where the command is executed. |
<sslmode> |
SSL connection mode. Set it to verify-ca to use a CA to check whether the service is trusted. |
For example, to connect to a DB instance through an SSL connection as user root, run the following command:
export PGSSLMODE="verify-ca" export PGSSLROOTCERT="/home/Ruby/ca.pem"
gsql -d postgres -h 10.10.0.11 -U jack -p 8000 -W Test@123
SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256)