Help Center/ GaussDB/ Getting Started/ Buying and Connecting to the GaussDB Instance Using gsql
Updated on 2024-09-13 GMT+08:00

Buying and Connecting to the GaussDB Instance Using gsql

This section describes how to use the gsql client to connect to a GaussDB instance you have bought on the GaussDB management console. For more methods of connecting to an instance, see Connecting to a GaussDB Instance.

Buying an Instance

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and project.
  3. Click in the upper left corner of the page and choose Databases > GaussDB.
  4. On the Instances page, click Buy DB Instance.
  5. On the displayed page, set Billing Mode, enter DB Instance Name, select Edition Type, DB Engine Version, DB Instance Type, and Deployment Model, and complete other configurations.

    • Billing Mode: Pay-per-use
    • Region and Project: Retain the default settings.
    • DB Instance Name: Enter a name that is easy to identify.
    • Edition Type: Enterprise edition
    • DB Engine Version: 8.103
    • DB Instance Type: Primary/Standby
    • Deployment Model: 1 primary + 2 standby
    • AZ: AZ1
    • Time Zone: Retain the default value.
    Figure 1 Billing mode and basic information

  6. Configure instance specifications.

    • Instance Specifications: Dedicated(1:4) and 4 vCPUs | 16 GB
    • Storage Type: Ultra-high I/O
    • Storage Space: 40 GB
    • Disk Encryption: Disable
    Figure 2 Specifications and storage

  7. Retain the default settings for the network information.

    Figure 3 Network configuration

  8. Configure the instance password and enterprise project.

    • Administrator Password: Set a strong password to improve security.
    • Confirm Password: Enter the administrator password again.
    • Enterprise Project: default
    • Retain the default values for other parameters.
    Figure 4 Database configuration

  9. Click Next, confirm the instance information, and click Submit.
  10. Go to the instance list.

    If status of the instance becomes Available, the instance has been created.

Buying an ECS

GaussDB provides the gsql tool to help you connect to the database using the command-line interface (CLI). You need to create an ECS in advance for installing the gsql tool.

  1. Log in to the management console.
  2. Click Buy ECS.
  3. Configure basic settings and click Next: Configure Network.
    • Region: Select the region of the GaussDB instance to be connected.
    • Billing Mode: Pay-per-use
    • AZ: Select the AZ of the GaussDB instance to be connected.
    • Image: EulerOS and EulerOS 2.5 64bit(40 GiB)
    • Retain the default values for other parameters.
    Figure 5 Basic settings
    Figure 6 Selecting an image

  4. Configure the ECS network and click Next: Configure Advanced Settings.
    • Network: Select the VPC of the GaussDB instance to be connected.
    • Security Group: Select the security group of the GaussDB instance to be connected.
    • EIP: Do Not Use
    Figure 7 Network configuration

  5. Configure a password for the ECS, set other parameters as required, and click Next: Confirm.
    • ECS Name: Enter a name that is easy to identify.
    • Password: Set a strong password to improve security.
    • Confirm Password: Enter the password again.
    • Retain the default values for other parameters.
    Figure 8 Advanced settings

  6. Confirm the configuration and click Apply Now.
  7. View the purchased ECS.

Obtaining the Driver Package

Download particular packages listed in Table 1 based on the version of your instance.

To prevent a software package from being tampered with during transmission or storage, download the corresponding verification package and perform the following steps to verify the software package:

  1. Upload the software package and verification package to the same directory on a Linux VM.
  2. Run the following command to verify the integrity of the software package:

    cat GaussDB_driver.zip.sha256 | sha256sum --check

    If OK is displayed in the command output, the verification is successful.

    GaussDB_driver.zip: OK

Connecting to a Database

  • Non-SSL connection
    1. Log in as the root user to the ECS you have created.
    2. Upload the client tool package and configure gsql environment variables.
      1. Run the following command to create the /tmp/tools directory for storing the client tool package:
        mkdir /tmp/tools
      2. Download the GaussDB_driver.zip driver package of the required version by referring to Obtaining the Driver Package, and upload it to the /tmp/tools directory of the created ECS.
      3. Run the following commands to decompress the GaussDB_driver.zip driver package:
        cd /tmp/tools
        unzip GaussDB_driver.zip
      4. Run the following commands to copy the decompressed GaussDB-Kernel_***_EULER_64bit-Gsql.tar.gz client tool package to the /tmp/tools directory:

        This section uses the gsql tool package suitable for the primary/standby instances running on Euler2.5_x86_64 as an example. The relative path of the tool package varies depending on where you decompressed it.

        cd /tmp/tools/GaussDB_driver/Centralized/Euler2.5_X86_64/
        cp GaussDB-Kernel_***_EULER_64bit-Gsql.tar.gz /tmp/tools
      5. Run the following commands to decompress the package:
        cd /tmp/tools
        tar -zxvf GaussDB-Kernel_***_EULER_64bit-Gsql.tar.gz
      6. Configure environment variables.

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

        vim ~/.bashrc

        Press G to move the cursor to the last line, press i to enter Insert mode, and type the following information. Then, press Esc to exit Insert mode, and run :wq to save the settings and exit.

        export PATH=/tmp/tools/bin:$PATH
        export LD_LIBRARY_PATH=/tmp/tools/lib:$LD_LIBRARY_PATH
        Run the following command to make the environment variables take effect permanently:
        source ~/.bashrc
    3. Enter the password when prompted to connect to the database.

      After an instance is created, a postgres database is generated by default. Database postgres is used an example.

      gsql -d postgres -h 10.0.0.0 -U root -p 8000
      Password for user root:
      • postgres indicates the name of the database to be connected.
      • 10.0.0.0 indicates the IP address of the instance. On the Basic Information page of the instance to be connected, obtain the IP address in the Node List area.
      • root indicates the username used to log in to the database.
      • 8000 indicates the port number of the database. On the Basic Information page of the instance to be connected, obtain the database port in the Network Information area.

      For more information about gsql commands, see Tool Reference.

  • SSL connection
    1. Log in to the management console.
    2. Click in the upper left corner and select a region and project.
    3. Click in the upper left corner of the page and choose Databases > GaussDB.
    4. On the Instances page, click the name of the target instance. In the Configuration area on the Basic Information page, click next to the SSL field to download the root certificate or certificate bundle.
    5. Upload the root certificate to the ECS or save it to the device to be connected to the GaussDB instance.

      Import the root certificate to the Linux ECS. For details, see How Can I Import the Root Certificate to a Windows or Linux OS?

    6. Connect to a GaussDB instance.
      A Linux ECS is used in this example. Run the following command to set environment variables on the ECS:
      export PGSSLMODE=<sslmode>
      export PGSSLROOTCERT=<ca-file-directory>

      gsql -h <host> -p <port> -d <database> -U <user>

      Table 2 Parameters

      Parameter

      Description

      <host>

      IP address of the DB instance. To obtain this parameter, go to the Basic Information page of the DB instance. The IP address can be found in the IP Address column of the Node List 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 Network Information area.

      <database>

      Name of the database (postgres by default).

      <user>

      Username of the GaussDB database account. The default administrator is root.

      <ca-file-directory>

      Path of the CA certificate for SSL connection.

      <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 postgres database through an SSL connection as user root, run the following commands on the ECS:

      export PGSSLMODE="verify-ca"
      export PGSSLROOTCERT="/home/Ruby/ca.pem"

      gsql -d postgres -h 10.0.0.0 -U root -p 8000

      Password for user root:

      For more information about gsql commands, see Tool Reference.

    7. Check the command output after you log in to the database. If information similar to the following is displayed, the SSL connection has been established.
      SSL connection (cipher: DHE-RSA-AES256-GCM-SHA384, bits: 256)

Follow-up Operations

After logging in to the instance, you can create alarm rules, set automated backup policies, create databases, and migrate data. For details, see: