Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Managed Service for PostgreSQL
  • Getting started
    • All guides
      • Viewing cluster logs
      • Performance diagnostics
      • Cluster and host status monitoring
      • Connecting to DataLens
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Enabling statistics collection
  • Getting session statistics
  • Getting query statistics
  • Getting query plan details
  1. Step-by-step guides
  2. Logs and monitoring
  3. Performance diagnostics

Performance diagnostics in Managed Service for PostgreSQL

Written by
Yandex Cloud
Updated at December 25, 2025
  • Enabling statistics collection
  • Getting session statistics
  • Getting query statistics
  • Getting query plan details

Managed Service for PostgreSQL provides a built-in tool for diagnosing your database cluster performance. This tool helps you analyze PostgreSQL performance metrics for sessions and queries.

To learn how to identify and resolve cluster performance issues, see the Performance analysis and optimization and Troubleshooting cluster performance sections.

Enabling statistics collectionEnabling statistics collection

Management console
CLI
Terraform
REST API
gRPC API

Enable the Statistics sampling option when creating a cluster or updating its settings. This option is disabled by default.

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

To enable statistics collection, add the --performance-diagnostics option to the cluster update command:

yc managed-postgresql cluster update <cluster_name_or_ID> \
    ...
    --performance-diagnostics enabled=true,`
                             `sessions-sampling-interval=<session_sampling_interval>,`
                             `statements-sampling-interval=<statement_sampling_interval> \
    ...

Allowed values:

  • sessions-sampling-interval: From 1 to 86400 seconds.
  • statements-sampling-interval: From 60 to 86400 seconds.
  1. Open the current Terraform configuration file describing your infrastructure.

    To learn how to create this file, see Creating clusters.

    For a complete list of configurable Managed Service for PostgreSQL cluster fields, refer to the Terraform provider guides.

  2. To set up statistics collection, add the performance_diagnostics block to the config section:

    resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
      ...
      config {
        ...
        performance_diagnostics {
          enabled                      = <activate_statistics_collection>
          sessions_sampling_interval   = <session_sampling_interval>
          statements_sampling_interval = <statement_sampling_interval>
        }
        ...
      }
      ...
    }
    

    Where:

    • enabled: Enable statistics collection, true or false.
    • sessions_sampling_interval: Session sampling interval, from 1 to 86400 seconds.
    • statements_sampling_interval: Statement sampling interval, from 60 to 86400 seconds.
  3. Validate your configuration.

    1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.

    2. Run this command:

      terraform validate
      

      Terraform will show any errors found in your configuration files.

  4. Confirm resource changes.

    1. Run this command to view the planned changes:

      terraform plan
      

      If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. Wait for the operation to complete.

    Timeouts

    The Terraform provider sets the following timeouts for Managed Service for PostgreSQL cluster operations:

    • Creating a cluster, including restoration from a backup: 30 minutes.
    • Updating a cluster: 60 minutes.
    • Deleting a cluster: 15 minutes.

    Operations exceeding the timeout are aborted.

    How can I change these timeouts?

    Add a timeouts section to the cluster description, e.g.:

    resource "yandex_mdb_postgresql_cluster" "<cluster_name>" {
      ...
      timeouts {
        create = "1h30m" # 1 hour 30 minutes
        update = "2h"    # 2 hours
        delete = "30m"   # 30 minutes
      }
    }
    
  1. Get an IAM token for API authentication and place it in an environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. To enable statistics collection when creating a cluster:

    1. Include configSpec.performanceDiagnostics option to the cURL command implementing the Cluster.Create method:

      curl \
        --request POST \
        --header "Authorization: Bearer $IAM_TOKEN" \
        --header "Content-Type: application/json" \
        --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters' \
        --data '{
                  "configSpec": {
                    "performanceDiagnostics": {
                      "enabled": <enable_statistics_collection>,
                      "sessionsSamplingInterval": "<session_sampling_interval>",
                      "statementsSamplingInterval": "<statement_sampling_interval>"
                    },
                    ...
                  },
                  ...
                }'
      

      Where configSpec.performanceDiagnostics represents the statistics collection settings:

      • enabled: Enable statistics collection, true or false.
      • sessionsSamplingInterval: Session sampling interval. Allowed values range from 1 to 86400.
      • statementsSamplingInterval: Statement sampling interval. Allowed values range from 60 to 86400.
    2. Check the server response to make sure your request was successful.

  3. To enable statistics collection when updating an existing cluster:

    1. Call the Cluster.Update method, for instance, via the following cURL request:

      Warning

      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the updateMask parameter as a single comma-separated string.

      curl \
        --request PATCH \
        --header "Authorization: Bearer $IAM_TOKEN" \
        --header "Content-Type: application/json" \
        --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>' \
        --data '{
                  "updateMask": "configSpec.performanceDiagnostics",
                  "configSpec": {
                    "performanceDiagnostics": {
                      "enabled": <enable_statistics_collection>,
                      "sessionsSamplingInterval": "<session_sampling_interval>",
                      "statementsSamplingInterval": "<statement_sampling_interval>"
                    }
                  }
                }'
      

      Where configSpec.performanceDiagnostics represents the statistics collection settings:

      • enabled: Enable statistics collection, true or false.
      • sessionsSamplingInterval: Session sampling interval. Allowed values range from 1 to 86400.
      • statementsSamplingInterval: Statement sampling interval. Allowed values range from 60 to 86400.
    2. Check the server response to make sure your request was successful.

  1. Get an IAM token for API authentication and place it in an environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume the repository contents are stored in the ~/cloudapi/ directory.

  3. To enable statistics collection when creating a cluster:

    1. Include the config_spec.performance_diagnostics option to the grpcurl command implementing the ClusterService.Create method:

      grpcurl \
        -format json \
        -import-path ~/cloudapi/ \
        -import-path ~/cloudapi/third_party/googleapis/ \
        -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \
        -rpc-header "Authorization: Bearer $IAM_TOKEN" \
        -d '{
              "config_spec": {
                "performance_diagnostics": {
                  "enabled": <enable_statistics_collection>,
                  "sessions_sampling_interval": "<session_sampling_interval>",
                  "statements_sampling_interval": "<statement_sampling_interval>"
                },
                ...
              },
              ...
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.postgresql.v1.ClusterService.Create
      

      Where config_spec.performance_diagnostics represents the statistics collection settings:

      • enabled: Enable statistics collection, true or false.
      • sessions_sampling_interval: Session sampling interval. Allowed values range from 1 to 86400.
      • statements_sampling_interval: Statement sampling interval. Allowed values range from 60 to 86400.
    2. Check the server response to make sure your request was successful.

  4. To enable statistics collection when updating an existing cluster:

    1. Call the ClusterService.Update method, for instance, via the following gRPCurl request:

      Warning

      The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the update_mask parameter as an array of paths[] strings.

      Format for listing settings
      "update_mask": {
          "paths": [
              "<setting_1>",
              "<setting_2>",
              ...
              "<setting_N>"
          ]
      }
      
      grpcurl \
        -format json \
        -import-path ~/cloudapi/ \
        -import-path ~/cloudapi/third_party/googleapis/ \
        -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/cluster_service.proto \
        -rpc-header "Authorization: Bearer $IAM_TOKEN" \
        -d '{
              "cluster_id": "<cluster_ID>",
              "update_mask": {
                "paths": [
                  "config_spec.performance_diagnostics"
                ]
              },
              "config_spec": {
                "performance_diagnostics": {
                  "enabled": <enable_statistics_collection>,
                  "sessions_sampling_interval": "<session_sampling_interval>",
                  "statements_sampling_interval": "<statement_sampling_interval>"
                }
              }
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.postgresql.v1.ClusterService.Update
      

      Where config_spec.performance_diagnostics represents the statistics collection settings:

      • enabled: Enable statistics collection, true or false.
      • sessions_sampling_interval: Session sampling interval. Allowed values range from 1 to 86400.
      • statements_sampling_interval: Statement sampling interval. Allowed values range from 60 to 86400.
    2. Check the server response to make sure your request was successful.

Getting session statisticsGetting session statistics

Management console
gRPC API
  1. Go to Managed Service for PostgreSQL.
  2. Click the name of your cluster and select the Performance diagnostics → Sessions tab.

To view session statistics:

  1. Specify the time interval.
  2. Optionally, configure filters.
  3. Select a data segment.

To show or hide individual categories, click the category name in the chart legend.

To see the query history within a session:

  1. Specify the time interval.
  2. Optionally, configure filters.
  1. Get an IAM token for API authentication and place it in an environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume the repository contents are stored in the ~/cloudapi/ directory.

  3. Call the PerformanceDiagnosticsService.ListRawSessionStates method, for instance, via the following gRPCurl request:

    grpcurl \
      -format json \
      -import-path ~/cloudapi/ \
      -import-path ~/cloudapi/third_party/googleapis/ \
      -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/perf_diag_service.proto \
      -rpc-header "Authorization: Bearer $IAM_TOKEN" \
      -d '{
            "cluster_id": "<cluster_ID>",
            "from_time": "<time_range_left_boundary>",
            "to_time": "<time_range_right_boundary>"
          }' \
      mdb.api.cloud.yandex.net:443 \
      yandex.cloud.mdb.postgresql.v1.PerformanceDiagnosticsService.ListRawSessionStates
    

    Where:

    • from_time: The start time of the time range in RFC-3339 format, e.g., 2024-09-18T15:04:05Z.
    • to_time: The end time of the time range in the same format as from_time.

    You can get the cluster ID from the folder’s cluster list.

  4. Check the server response to make sure your request was successful.

To learn what statistics you can get, see the PostgreSQL guides.

Getting query statisticsGetting query statistics

Management console
gRPC API
  1. Go to Managed Service for PostgreSQL.
  2. Click the name of your cluster and select the Performance diagnostics → Queries tab.

To view query statistics for a specific time interval:

  1. Select the time interval.
  2. Optionally, configure filters.

To get details on relative changes in query statistics:

  1. In the Interval 1 field, select the time interval to use as the baseline for calculations.
  2. In the Interval 2 field, select the time interval to compare against the baseline interval.
  3. Optionally, configure filters.

Suppose, 10 SELECT * FROM cities queries were executed in the first interval and 20 in the second. A comparison of the statistics will show a +100% difference for the query count metric (the Calls table column).

  1. Get an IAM token for API authentication and place it in an environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume the repository contents are stored in the ~/cloudapi/ directory.

  3. Call the PerformanceDiagnosticsService.ListRawStatements method, for instance, via the following gRPCurl request:

    grpcurl \
      -format json \
      -import-path ~/cloudapi/ \
      -import-path ~/cloudapi/third_party/googleapis/ \
      -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/perf_diag_service.proto \
      -rpc-header "Authorization: Bearer $IAM_TOKEN" \
      -d '{
            "cluster_id": "<cluster_ID>",
            "from_time": "<time_range_left_boundary>",
            "to_time": "<time_range_right_boundary>"
          }' \
      mdb.api.cloud.yandex.net:443 \
      yandex.cloud.mdb.postgresql.v1.PerformanceDiagnosticsService.ListRawStatements
    

    Where:

    • from_time: The start time of the time range in RFC-3339 format, e.g., 2024-09-18T15:04:05Z.
    • to_time: The end time of the time range in the same format as from_time.

    You can get the cluster ID from the folder’s cluster list.

  4. Check the server response to make sure your request was successful.

To learn more about available statistics, refer to the pg_stat_statements and pg_stat_kcache extension guides.

Getting query plan detailsGetting query plan details

The auto_explain module allows you to log slow query plans automatically, eliminating the need for the EXPLAIN command. It helps to identify non-optimized queries. This module uses the general PostgreSQL log.

You can enable query logging in the DBMS settings:

  1. In the Shared preload libraries field, select auto_explain.

  2. Enable Auto explain log analyze.

  3. Configure the auto_explain module settings:

    Warning

    Selecting 0 for Auto explain log min duration or enabling Auto explain log timing can significantly reduce cluster performance.

    • Auto explain log buffers
    • Auto explain log min duration
    • Auto explain log nested statements
    • Auto explain log timing
    • Auto explain log triggers
    • Auto explain log verbose
    • Auto explain sample rate

Was the article helpful?

Previous
Viewing cluster logs
Next
Cluster and host status monitoring
© 2026 Direct Cursus Technology L.L.C.