MogDB
Ecological Tools
Doc Menu

Use CLI to Access MogDB

This document introduces how to use CLI to access MogDB. gsql is a MogDB-provided database connection tool running in the CLI. gsql provides basic and advanced functions of databases to facilitate user operations.

Confirming Connection Information

You can use a client tool to connect a database through the primary node of the database. Before the connection, obtain the IP address of the primary node of the database and the port number of the server where the primary node of the database is deployed.

Procedure

  1. Log in to the primary node of the database as the OS user omm.
  2. Run the gs_om -t status --detail command to query instances in the MogDB cluster.

    gs_om -t status --detail
    [  Datanode State   ]
    
    node                 node_ip         instance                state
    ---------------------------------------------------------------------------------
    1  mogdb-kernel-0005 172.16.0.176    6001 /mogdb/data/db1 P Primary Normal

    For example, the server IP address where the primary node of the database is deployed is 172.16.0.176. The data path of the primary node of the database is /mogdb/data/db1.

  3. Confirm the port number of the primary node of the database.

    View the port number in the postgresql.conf file in the data path of the primary database node obtained in step 2. The command is as follows:

    cat /mogdb/data/db1/postgresql.conf | grep port
    port = 26000    # (change requires restart)
    #comm_sctp_port = 1024   # Assigned by installation (change requires restart)
    #comm_control_port = 10001  # Assigned by installation (change requires restart)
          # supported by the operating system:
          # e.g. 'localhost=10.145.130.2 localport=12211 remotehost=10.145.130.3 remoteport=12212, localhost=10.145.133.2 localport=12213 remotehost=10.145.133.3 remoteport=12214'
          # e.g. 'localhost=10.145.130.2 localport=12311 remotehost=10.145.130.4 remoteport=12312, localhost=10.145.133.2 localport=12313 remotehost=10.145.133.4 remoteport=12314'
          #   %r = remote host and port
    alarm_report_interval = 10
    support_extended_features=true

    26000 in the first line is the port number of the primary database node.

Prerequisites

MogDB has been installed and the connection information has been confirmed.

Connecting a Database

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

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

    Run the following command to connect the postgres database:

    gsql -d postgres -p 26000

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

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

    gsql ((MogDB 2.0.1 build f892ccb7) compiled at 2021-07-09 16:12:59 commit 0 last mr  )
    Non-SSL connection (SSL connection is recommended when requiring high-security)
    Type "help" for help.
    
    postgres=#

    User omm is the administrator, and therefore postgres=# is displayed. If you log in to and connect the database as a common user, postgres=> is displayed.

    Non-SSL connection indicates that the database is not connected in SSL mode. If high security is required, connect the database in SSL mode.

  3. Exit the database.

    postgres=# \q