Quick Start for AnalyticDB for PostgreSQL on CloudBox

更新时间:
复制 MD 格式

This topic describes how to create, connect to, and use an AnalyticDB for PostgreSQL on CloudBox instance.

Step 1: Create an instance

Before you begin, you must create an AnalyticDB for PostgreSQL on CloudBox instance.

  1. Log on to the AnalyticDB for PostgreSQL console.
  2. In the upper-right corner of the page, click Create Instance to open the buy page.

  3. If you create an instance for the first time, you must create a service-linked role. In the Create Service Linked Role dialog box, click OK.

  4. On the instance purchase page, configure the following parameters:
    Configuration ItemDescription
    Product TypeSelect Pay-as-you-go.
    Region and ZoneSelect the custom Region and Zone for CloudBox.
    Network TypeThis is fixed to VPC.
    VPC and vSwitchSelect an available VPC and vSwitch.

    If no VPC or vSwitch is available in the current zone, follow the on-screen instructions to go to the VPC console and create them. After you create them, return to the AnalyticDB for PostgreSQL purchase page and click the 刷新 icon to refresh.

    Instance Resource TypeSelect Storage-elastic Mode.
    Instance EditionSelect High-availability Edition.
    Number of master nodesThis is fixed to 1.
    Node specifications (segment)Select the specifications for compute nodes.
    Number of nodes (segment)Select the number of compute nodes. Increasing the number of nodes can linearly improve performance.
    Storage Disk TypeSelect the disk type for data storage.
    Encryption TypeSelect Unencrypted or Disk Encryption.
    Node Storage Capacity (segment)The storage capacity for each node in the instance. The storage capacity can range from 50 GB to 4000 GB and must be a multiple of 50.
  5. Click Buy Now.

  6. On the Confirm Order page, confirm the parameter settings, agree to the Terms of Service, and click Activate Now.

  7. Click Management Console to return to the Instance List page.

    Note

    Instance initialization for AnalyticDB for PostgreSQL takes 5 to 20 minutes. You can perform subsequent operations only when the instance is in the Running state.

Step 2: Create an initial account

Before you connect to the database, you must create an initial account for the AnalyticDB for PostgreSQL instance.

  1. Log on to the AnalyticDB for PostgreSQL console.
  2. In the upper-left corner of the console, select a region.
  3. Find the instance that you want to manage and click the instance ID.
  4. In the left-side navigation pane, click Account Management.

  5. On the Account Management page, click Create Account in the upper-right corner.

  6. In the Create Account panel, specify the Account and New Password parameters as prompted, and then confirm the password.

  7. Click OK.

Step 3: Log on to the database

Log on to the database to manage your data. This topic uses Data Management Service (DMS) as an example to show how to log on to the database.

  1. Log on to the AnalyticDB for PostgreSQL console.
  2. In the upper-left corner of the console, select a region.
  3. Find the instance that you want to manage and click the instance ID.
  4. Click Log On to Database in the upper-right corner.

  5. Optional:The first time you use DMS, you must authorize DMS to access AnalyticDB for PostgreSQL resources. Click Go to RAM role authorization and grant permissions. For more information, see Authorize DMS to access cloud resources.

  6. In the Log on to Database Instance dialog box, specify Database Account and Database password.

  7. Click Login.

  8. On the SQL Console tab, execute SQL statements to manage data.

Step 4: Write data

After you log on to the database, you can perform operations such as creating, retrieving, updating, and deleting data. This section guides you through creating a table and writing one million rows of test data.

  1. Create a test table named customer.
    The statement to create the table is as follows:
    CREATE TABLE CUSTOMER(id int, name varchar, md5 varchar) DISTRIBUTED BY (id) ;
  2. Create a function to generate random test data.
    The statement to create the function is as follows:
    CREATE OR REPLACE FUNCTION f_random_str(length INTEGER)
    RETURNS character varying AS $$
    DECLARE
        result varchar(50);
    BEGIN
        SELECT array_to_string(ARRAY(SELECT chr((65 + round(random() * 25)) :: integer)
        FROM generate_series(1,length)), '') INTO result;
    
        return result;
    END;
    $$ LANGUAGE plpgsql;
  3. Insert one million rows of random test data.
    The statement to insert the test data is as follows:
    INSERT INTO customer SELECT *, f_random_str(5), md5(random()::text) FROM generate_series(1, 1000000);
  4. Query the total number of rows in the customer table.
    The query statement is as follows:
    SELECT count() FROM customer;

    The following example shows the returned result:

    The number of returned rows