All Products
Search
Document Center

Simple Log Service:Associate a PostgreSQL data source

Last Updated:Oct 29, 2025

This topic describes how to create an external store to associate Simple Log Service (SLS) with a PostgreSQL database.

Prerequisites

  • You have collected data in SLS. For more information, see Data collection.

  • You have installed the SLS CLI and configured the service endpoint and AccessKey pair.

  • You have stored data in an Alibaba Cloud RDS for PostgreSQL database, an Alibaba Cloud ADB for PostgreSQL database, or an Alibaba Cloud Hologres instance.

  • The PostgreSQL database is in an Alibaba Cloud virtual private cloud (VPC). The RDS instance, ADB instance, or Hologres instance must be in the same region as the SLS project.

    Important

    You cannot connect to a PostgreSQL database using an Internet endpoint.

Background information

The external store feature of SLS lets you associate SLS with an Alibaba Cloud RDS for PostgreSQL database, an Alibaba Cloud ADB for PostgreSQL database, or an Alibaba Cloud Hologres instance. You can also write query and analysis results to a PostgreSQL database for further processing.

Procedure

1. Configure a whitelist

RDS for PostgreSQL database

Add the following CIDR blocks to the whitelist: 100.104.0.0/16, 11.194.0.0/16, and 11.201.0.0/16. For more information, see Set a whitelist.

Alibaba Cloud Hologres

Add the following CIDR blocks to the whitelist: 100.104.0.0/16, 11.194.0.0/16, and 11.201.0.0/16. For more information, see IP whitelist.

ADB for PostgreSQL database

Add the following CIDR blocks to the whitelist: 100.104.0.0/16, 11.194.0.0/16, and 11.201.0.0/16. For more information, see Configure a whitelist.

2. Create an ExternalStore

  1. Log on to the server where the CLI is installed. On the command line, run the touch command to create a configuration file named /home/shell/config.json. Add the following script to the config.json file. You must replace the values of the region, vpc-id, host, port, username, password, db, and table parameters with your actual values.

    Parameter description

    Example

    {
        "externalStoreName":"sls_join_meta_store",
        "storeType":"postgresql",
        "parameter":{
            "region":"cn-qingdao",
            "vpc-id":"vpc-m5eq4irc1pucp*******",
            "host":"localhost",
            "port":"3306",
            "username":"user",
            "password":"****",
            "db":"scmc",
            "table":"join_meta"
        }
    }

    externalStoreName

    The name of the ExternalStore. The name must be in lowercase.

    storeType

    The type of the data source. Set the value to postgresql.

    region

    The region, such as cn-wulanchabu or cn-hangzhou.

    Important

    The RDS instance, Hologres instance, or ADB instance must be in the same region as the SLS project.

    vpc-id

    The ID of the VPC where the database is located. This parameter varies based on the database type:

    • If your RDS for PostgreSQL instance is in a VPC, set vpc-id to the ID of that VPC.

    • If your ADB for PostgreSQL database is in a VPC, set vpc-id to the ID of the VPC that contains the instance.

    • If you use an Alibaba Cloud Hologres database in a VPC, set vpc-id to the ID of the Hologres instance's VPC.

    host  

    The internal endpoint of the database.

    port

    The port number of the database instance.

    username

    The username of the database.

    password

    The password of the database.

    db

    The name of the database.

    table

    The name of the database table. The following formats are supported:

    1. `table_name`, for example, `test`.

    2. `schema_name.table_name`, for example, `public.test`.

  1. Run the following command on the command line to create an ExternalStore. In the command, replace project_name with the name of your SLS project. This topic uses log-rds-demo as an example.

    aliyunlog log create_external_store --project_name="log-rds-demo" --config="file:///home/shell/config.json" 
  2. Query the information about the ExternalStore. If the command runs successfully, no response is returned. Run the aliyunlog log get_external_store --project_name="log-rds-demo" --store_name="sls_join_meta_store" --format-output=json command to query the details of the external data source. The following information is returned:

    {
     "externalStoreName": "sls_join_meta_store",
     "parameter": {
     "db": "postgres",
     "host": "rm-bp1******rm76.pg.rds.aliyuncs.com",
     "port": "5432",
     "region": "cn-wulanchabu",
     "table": "test",
     "timezone": "",
     "username": "user",
     "vpc-id": "vpc-m5eq4irc1pucp*******"
     },
     "storeType": "postgresql"
    }

3. Query the associated PostgreSQL data

After you create the external store, go to the SLS console. In the project named log-rds-demo, click any logstore and run the * | select * from sls_join_meta_store query statement to query the associated PostgreSQL data.

image

Related operations

  • Update the PostgreSQL external store.

    aliyunlog log update_external_store --project_name="log-rds-demo" --config="file:///home/shell/config.json" 
  • Delete the PostgreSQL external store.

    aliyunlog log delete_external_store --project_name="log-rds-demo" --store_name=sls_join_meta_store