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.
- Log in as the OS user omm to the primary node of the database. 
- 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- 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=#- 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. 
- 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';
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.
- 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: - You can run the following command to query the openGauss version and copyright information: - openGauss=# \copyright
- You can run the following command to obtain the help syntax of various openGauss SQL commands: - openGauss=# \h
- You can run the following command to query all data and description information in the openGauss: - openGauss=# \l
 
- Exit the database. - openGauss=# \q- 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.