PostgreSQL monitoring

PostgreSQL server performance from postgres-exporter

SkyWalking leverages postgres-exporter for collecting metrics data from PostgreSQL. It leverages OpenTelemetry Collector to transfer the metrics to OpenTelemetry receiver and into the Meter System.

Data flow

  1. postgres-exporter collect metrics data from PostgreSQL.
  2. OpenTelemetry Collector fetches metrics from postgres-exporter via Prometheus Receiver and pushes metrics to SkyWalking OAP Server via the OpenCensus gRPC Exporter or OpenTelemetry gRPC exporter.
  3. The SkyWalking OAP Server parses the expression with MAL to filter/calculate/aggregate and store the results.

Set up

  1. Set up postgres-exporter.
  2. Set up OpenTelemetry Collector . For details on Prometheus Receiver in OpenTelemetry Collector, refer to here.
  3. Config SkyWalking OpenTelemetry receiver.

PostgreSQL Monitoring

PostgreSQL monitoring provides monitoring of the status and resources of the PostgreSQL server.PostgreSQL server as a Service in OAP, and land on the Layer: POSTGRESQL.

Supported Metrics

Monitoring PanelUnitMetric NameDescriptionData Source
Shared BuffersMBmeter_pg_shared_buffersThe number of shared memory buffers used by the serverpostgres-exporter
Effective CacheGBmeter_pg_effective_cacheThe planner's assumption about the total size of the data cachespostgres-exporter
Maintenance Work MemMBmeter_pg_maintenance_work_memThe maximum memory to be used for maintenance operationspostgres-exporter
Seq Page Costmeter_pg_seq_page_costThe planner's estimate of the cost of a sequentially fetched disk page.postgres-exporter
Random Page Costmeter_pg_random_page_costThe planner's estimate of the cost of a nonsequentially fetched disk page.postgres-exporter
Max Worker Processesmeter_pg_max_worker_processesMaximum number of concurrent worker processespostgres-exporter
Max WAL SizeGBmeter_max_wal_sizeThe WAL size that triggers a checkpointpostgres-exporter
Max Parallel Workersmeter_pg_max_parallel_workersThe maximum number of parallel processes per executor nodepostgres-exporter
Work MemMBmeter_pg_max_work_memThe maximum memory to be used for query workspaces.postgres-exporter
Fetched Row Trendmeter_pg_fetched_rows_rateThe trend of the number of rows fetched by queries in this database.postgres-exporter
Inserted Row Trendmeter_pg_inserted_rows_rateThe trend of the number of rows inserted by queries in this database.postgres-exporter
Updated Row Trendmeter_pg_updated_rows_rateThe trend of the number of rows updated by queries in this database.postgres-exporter
Deleted Row Trendmeter_pg_deleted_rows_rateThe trend of the number of rows deleted by queries in this database.postgres-exporter
Returned Row Trendmeter_pg_returned_rows_rateThe trend of the number of rows returned by queries in this database.postgres-exporter
Committed Transactions Trendmeter_pg_committed_transactions_rateThe trend of the number of transactions in this database that have been committedpostgres-exporter
Rolled Back Transactions Trendmeter_pg_rolled_back_transactions_rateThe trend of the number of transactions in this database that have been rolled backpostgres-exporter
Buffers Trendmeter_pg_buffers_alloc meter_pg_buffers_checkpoint meter_pg_buffers_clean meter_pg_buffers_backend_fsync meter_pg_buffers_backendThe trend of the number of bufferspostgres-exporter
Conflicts Trendmeter_pg_conflicts_rateThe trend of the number of queries canceled due to conflicts with recovery in this databasepostgres-exporter
Deadlock Trendmeter_pg_deadlocks_rateThe trend of the number of deadlocks detected in this databasepostgres-exporter
Cache Hit Rate%meter_pg_cache_hit_rateThe rate of cache hitpostgres-exporter
Temporary Files Trendmeter_pg_temporary_files_rateThe rate of total amount of data written to temporary files by queries in this database. All temporary files are counted, regardless of why the temporary file was created, and regardless of the log_temp_files settingpostgres-exporter
Checkpoint Stat Trendmeter_pg_checkpoint_write_time_rate meter_pg_checkpoint_sync_time_rate meter_pg_checkpoint_req_rate meter_pg_checkpoint_timed_rateThe trend of checkpoint statpostgres-exporter
Active Sessionsmeter_pg_active_sessionsThe number of connections which state is activepostgres-exporter
Idle Sessionsmeter_pg_idle_sessionsThe number of connections which state is idle,idle in transaction or idle in transaction (aborted)postgres-exporter
Locks Countmeter_pg_locks_countNumber of lockspostgres-exporter

Customizations

You can customize your own metrics/expression/dashboard panel. The metrics definition and expression rules are found in /config/otel-rules/postgresql.yaml. The PostgreSQL dashboard panel configurations are found in /config/ui-initialized-templates/postgresql.

Collect sampled slow SQLs

SkyWalking leverages fluentbit or other log agents for collecting slow SQL statements from PostgreSQL.

Data flow

  1. fluentbit agent collects slow sql logs from PostgreSQL.
  2. fluentbit agent sends data to SkyWalking OAP Server using native log APIs via HTTP.
  3. The SkyWalking OAP Server parses the expression with LAL to parse/extract and store the results.

Set up

  1. Set up fluentbit.
  2. Config fluentbit
  3. Config PostgreSQL to enable slow log. Example.

Slow SQL Monitoring

Slow SQL monitoring provides monitoring of the slow SQL statements of the PostgreSQL server. PostgreSQL Cluster is cataloged as a Layer: POSTGRESQL Service in OAP. Each PostgreSQL server is cataloged as an Instance in OAP.

Supported Metrics

Monitoring PanelUnitMetric NameDescriptionData Source
Slow Statementsmstop_n_database_statementThe latency and statement of PostgreSQL slow SQLsfluentbit

Customizations

You can customize your own metrics/expression/dashboard panel. The slowsql expression rules are found in /config/lal/pgsql-slowsql.yaml The PostgreSQL dashboard panel configurations are found in /config/ui-initialized-templates/postgresql.