All Products
Search
Document Center

Simple Log Service:Collect PostgreSQL query results

Last Updated:Jul 03, 2025

This topic describes how to create a Logtail configuration in the Simple Log Service console to collect PostgreSQL query results.

Prerequisites

  • Logtail V0.16.0 or later is installed on your Linux server or Logtail V1.0.0.8 or later is installed on your Windows server. For more information, see Install Logtail on a Linux server or Install Logtail on a Windows server.

    Important

    Make sure that the server on which Logtail is installed can connect to the database from which you want to collect PostgreSQL query results.

  • The IP address of the server on which Logtail is installed is added to a whitelist of the PostgreSQL database from which you want to collect PostgreSQL query results.

    For more information about how to configure an IP address whitelist for an ApsaraDB RDS for PostgreSQL instance, see Configure an IP address whitelist.

Features

  • You can collect query results from PostgreSQL databases.

  • You can configure paged query settings.

  • You can specify time zones.

  • You can specify timeout periods.

  • You can save the values of the CheckPoint field.

  • You can specify the maximum number of logs that can be collected at a time.

Procedure

  1. Log on to the Simple Log Service console.

  2. In the Import Data section, select Custom Data Plug-in.

  3. Select the project and Logstore. Then, click Next.

  4. In the Machine Group Configurations step, configure a machine group.

    1. Configure the Scenario and Installation Environment parameters based on your business requirements.

      Important

      You must configure the Scenario and Installation Environment parameters regardless of whether a machine group is available. The parameter settings affect subsequent configurations.

    2. Make sure that a machine group is displayed in the Applied Server Groups section and click Next.

      Machine group available

      Select a machine group from the Source Machine Group section.

      image

      No machine group available

      Click Create Machine Group. In the Create Machine Group panel, configure the parameters. You can set the Machine Group Identifier parameter to IP Address or Custom Identifier. For more information, see Create a custom identifier-based machine group or Create an IP address-based machine group.

      Important

      If you apply a machine group immediately after you create the machine group, the heartbeat status of the machine group may be FAIL. This issue occurs because the machine group is not connected to Simple Log Service. To resolve this issue, you can click Automatic Retry. If the issue persists, see What do I do if no heartbeat connections are detected on Logtail?

  5. In the Configure Data Source step, set the Configuration Name and Plug-in Configuration parameters, and then click Next.

    • inputs is required and is used to configure the data source settings for the Logtail configuration.

      Important

      You can specify only one type of data source in inputs.

    • processors is optional and is used to configure the data processing settings for the Logtail configuration to parse data. You can specify one or more processing methods.

      If your logs cannot be parsed based only on the setting of inputs, you can configure processors in the Plug-in Configuration field to add plug-ins for data processing. For example, you can extract fields, extract log time, mask data, and filter logs. For more information, see Overview of Logtail plug-ins for data processing.

  6. Create indexes and preview data. Then, click Next. By default, full-text indexing is enabled in Simple Log Service. You can also manually create field indexes for the collected logs or click Automatic Index Generation. Then, Simple Log Service generates field indexes. For more information, see Create indexes.

    Important

    If you want to query all fields in logs, we recommend that you use full-text indexes. If you want to query only specific fields, we recommend that you use field indexes. This helps reduce index traffic. If you want to analyze fields, you must create field indexes. You must include a SELECT statement in your query statement for analysis.

  7. Click Query Log. You are redirected to the query and analysis page of your Logstore.

    You must wait approximately 1 minute for the indexes to take effect. Then, you can view the collected logs on the Raw Logs tab. For more information, see Guide to log query and analysis.

Modify the Logtail configuration on the Logtail server

If you do not enter real information for parameters such as Address, User, and Password in Plug-in Config when you create a Logtail configuration, you can modify the parameters after the Logtail configuration is delivered to the Logtail server.

Linux

  1. Log on to the Logtail server.

  2. Find the service_pgsql keyword in the /usr/local/ilogtail/user_log_config.json file and modify parameters such as Address, User, and Password.

  3. Run the following command to restart Logtail:

    sudo /etc/init.d/ilogtaild stop; sudo /etc/init.d/ilogtaild start

Windows

  1. Log on to the Logtail server.

  2. Find the service_pgsql keyword in the C:\Program Files\Alibaba\Logtail\user_log_config.json file, and modify parameters such as Address, User, and Password.

    The file locations differ between Windows 64-bit operating systems and Windows 32-bit operating systems. For more information, see Logtail configuration files and record files.

  3. Restart Logtail.

    1. Choose Start > Control Panel > Administrative Tools > Services.

    • In the Services dialog box, select the corresponding service.

      • For Logtail V0.x.x.x, select LogtailWorker.

      • For Logtail V1.0.0.0 or later, select LogtailDaemon.

    • Right-click and select the desired action, such as Start, Stop, or Restart.

Troubleshooting

If no data is displayed on the preview page or query page after logs are collected by using Logtail, you can troubleshoot the errors based on the instructions that are provided in What do I do if errors occur when I use Logtail to collect logs?

Sample database table and sample logs

This section provides a sample database table of a PostgreSQL database and sample logs that are collected by Logtail.

  • Sample database table

    // Create a table. 
    CREATE TABLE IF NOT EXISTS specialalarmtest (
        id BIGSERIAL NOT NULL,
        time TIMESTAMP NOT NULL,
        alarmtype varchar(64) NOT NULL,
        ip varchar(16) NOT NULL,
        COUNT INT NOT NULL,
        PRIMARY KEY (id)
    );
    
    // Insert data. 
    insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 0);
    insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 1);
    insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 2);
    insert into specialalarmtest (time, alarmtype, ip, count) values(now(), 'NO_ALARM', '10.10.***.***', 3);
                            
  • Sample logs Sample logs