• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. User Guide
  4. Getting Started
  5. Step 3: Connecting to a Cluster

Step 3: Connecting to a Cluster

Scenario

This section describes how to connect to a database through a database client after you have created a data warehouse cluster. You can refer to the following guidance to use the gsql client tool provided by DWS to connect to the database in a cluster.

  1. Preparing an ECS: The gsql client of DWS remotely connects to the database in a data warehouse cluster on an ECS.

    In this example, the gsql client provided by DWS is used to access the cluster through the public network address. If you already have a qualified ECS, skip this step.

  2. Obtaining the Public Network Address of the Cluster: The DWS client connects to the database through the public network address.
  3. Using the ECS to Connect to a Cluster: Users can log in to the ECS, download and configure the DWS client, and connect to the database in the cluster.
NOTE:

You can also use other open-source PostgreSQL clients, such as pgAdmin, to connect to the databases and perform database operations. For details, see section Using pgAdmin to Connect to a Cluster.

Prerequisites

  • You have obtained the database administrator password of the cluster. The database administrator password has been set in Step 2: Creating a Cluster.
  • You have obtained the port number, AZ, VPC, and security group of the created cluster. For details, see section Step 2: Creating a Cluster.

Preparing an ECS

For details about how to create an ECS, see section Getting Started > Creating and Logging In to a Linux ECS in the Elastic Cloud Server User Guide.

The ECS must meet the following requirements:

  • The ECS and data warehouse cluster must belong to the same region and AZ.
  • If you use the gsql client provided by DWS to connect to the data warehouse cluster, the ECS image must meet the following requirements:

    There is no special requirement for the image's specifications. The image's OS must be one of the following Linux OSs supported by the gsql client:

    • The RedHat x64 client can be used on the following OSs:
      • RHEL 6.4/6.5/6.6/6.7/7.1/7.2
      • CentOS 6.4/6.5/6.6/6.7
      • EulerOS 2.0 SP2
    • The SUSE x64 client can be used on the following OSs:

      SLES11 SP1/SP2/SP3/SP4

  • If the client accesses the cluster using the private network address, ensure that the created ECS is in the same VPC as the data warehouse cluster.

    For details about VPC operations, see section VPC and Subnet in the Virtual Private Cloud User Guide.

  • If the client accesses the cluster using the public network address, ensure that both created ECS and the data warehouse cluster have an EIP.

    When creating an ECS, you need to set EIP to Automatically assign to bind to the EIP.

    For details about how to bind to an EIP, see section Elastic IP Address in the Virtual Private Cloud User Guide.

  • The security group rules of the ECS must enable communication between the ECS and the port that the data warehouse cluster uses to provide services.

    For details about security group operations, see Security > Security Group in the Virtual Private Cloud User Guide.

    Ensure that the security group of the ECS contains rules meeting the following requirements. If the rules do not exist, add them to the security group:

    • Transfer Direction: Outbound
    • Protocol/Application: The value must contain TCP, for example, TCP and All.
    • Port Range: The value must contain the database port that provides services in the data warehouse cluster. For example, set this parameter to 1-65535 or a specific DWS database port.
    • Destination: The IP address set here must contain the IP address of the cluster to be connected. For example, set this parameter to 0.0.0.0/0 or the specific connection address of the data warehouse cluster.
  • The security group rules of the data warehouse cluster must ensure that DWS can receive network access requests from clients.
    Ensure that the cluster's security group contains rules meeting the following requirements. If the rules do not exist, add them to the security group:
    • Transfer Direction: Inbound
    • Protocol/Application: The value must contain TCP, for example, TCP and All.
    • Port Range: Set this parameter to the database port that provides services in the data warehouse cluster, for example, 8000.
    • Source: The IP address set here must contain the IP address of the DWS client host, for example, 192.168.0.10/32.

Obtaining the Public Network Address of the Cluster

  1. Log in to the management console at https://console.otc.t-systems.com/dws/.
  2. In the navigation tree on the left, click Cluster Management.
  3. In the cluster list, select a created cluster (for example, dws-demo) click next to Cluster Name to obtain the public network address. Save this information.

    The public network address will be used to connect to the database in the cluster in Step 6.

    Figure 1 Cluster management

Using the ECS to Connect to a Cluster

  1. Remotely log in to an ECS using SSH.

    For details about more login methods, see section Getting Started > Creating and Logging In to a Linux ECS in the Elastic Cloud Server User Guide.

  2. In the ECS Linux command window, run the following commands to create a dws directory and switch to the directory:

    mkdir dws

    cd dws

  3. In the ECS Linux command window, run the Wget tool to download the DWS client.

    wget https://obs.otc.t-systems.com/dws/download/dws_client_redhat_x64.tar.gz --no-check-certificate

    The client contains database connection tool gsql and the script for testing the sample data.

    NOTE:

    You can also log in to the DWS management console to download the DWS client. For details, see section Downloading the Client.

  4. In the ECS Linux command window, run the following command to decompress the DWS client:

    tar -xvf dws_client_redhat_x64.tar.gz

  5. In the ECS Linux command window, run the following command to configure the DWS client:

    source gsql_env.sh

    If the following information is displayed, the DWS client is successfully configured:

    All things done.

  6. In the ECS Linux command window, run the following command to use the gsql tool to connect to the database in the data warehouse cluster:

    gsql -d <Database name> -h <Public network address of the cluster> -U <Administrator> -p <Data warehouse port number> -r

    Run the following command to connect to the postgres database in the data warehouse cluster:

    gsql -d postgres -h 10.168.0.74 -U dbadmin -p 8000 -r

    If the following information is displayed after you enter the password as prompted, the connection is successful:

    postgres=>
    NOTE:

    The gsql client can also connect to a cluster in SSL mode. The SSL connection mode has higher security than the common mode. You are advised to enable SSL connection (enabled by default) in the cluster and connect the client to the cluster in SSL mode. For details, see section Using the gsql Client to Connect to a Cluster.