DEV Community

wanglei
wanglei

Posted on

gsql Connection and Usage

gsql Connection and Usage
gsql provided by openGauss 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 local database. You need to provide a database name and a port number of the primary database node.

1.Log in as the OS user omm to the primary node of the database.

2.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.

Run the following command to connect to the postgres database:

gsql -d postgres -p 8000
Enter fullscreen mode Exit fullscreen mode

postgres is the name of the database to be connected, and 8000 is the port number of the database primary node. Replace the values as required.

If information similar to the following is displayed, the connection succeeds:

gsql((openGauss x.x.x build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=# 
Enter fullscreen mode Exit fullscreen mode

User omm is the administrator, and DBNAME=# is displayed. If you log in to and connect to the database as a common user, DBNAME=> is displayed, prompting you to enter SQL statements.

Non-SSL connection indicates that the database is not connected in SSL mode.

3.You are advised to change the password upon the first login to improve security. The command is as follows:

openGauss=# ALTER ROLE omm IDENTIFIED BY 'XXXXXXXX' REPLACE 'XXXXXXXX';
Enter fullscreen mode Exit fullscreen mode

_ NOTE:

Contain at least eight characters.
Cannot be the same as the username, the current password, or the current password in an inverted sequence.
Contain at least three of the following: uppercase characters (A to Z), lowercase characters (a to z), digits (0 to 9), and other characters (limited to ~!@#$%^&*()-=+|[{}];:,<.>/?).
The SSL certificate is generated during the installation. The certificate is stored in {gaussdbAppPath}/share/sslcert/om, where {gaussdbAppPath} is the program installation directory specified in the openGauss configuration file of the cluster.

4.gsql provides advanced functions for you to use the database.

The gsql program has some meta-commands that are not SQL commands. They begin with a backslash (). For example:

(1).You can run the following command to query the openGauss version and copyright information:

openGauss=# \copyright
Enter fullscreen mode Exit fullscreen mode

(2).You can run the following command to obtain the help syntax of various openGauss SQL commands:

openGauss=# \h
Enter fullscreen mode Exit fullscreen mode

(3).You can run the following command to query all data and description information in the openGauss:


openGauss=# \l
Enter fullscreen mode Exit fullscreen mode

5.Exit the database.

""

openGauss=# \q
Enter fullscreen mode Exit fullscreen mode

By default, a client is automatically disconnected if it remains idle for a period longer than 10 minutes (the default value of session_timeout) after connecting to the database.

Top comments (0)