Skip to main content
Version: NG-3.1

PostgreSQL

Introduction

PostgreSQL is a powerful open-source relational database management system (RDBMS). It is known for its extensibility, standards compliance, and robust feature set.

Getting Started

Compatibility

The PostgreSQL O11ySource supports PostgreSQL versions 14 and later.

Data Collection Method

vuSmartMaps collects health and performance data from Postgresql server through a data collector deployed within the vuSmartMaps. Logs are collected using the log collection probe of the OmniAgent.

Prerequisites

Dependent Configuration

To configure this O11ySource, create a 'credential' of type 'user' under the 'Definition' tab.

Inputs for Configuring Data Source

  • Instance Name: Please enter the name of the PostgreSQL instance. This should be a unique identifier for the PostgreSQL deployment you want to monitor.
  • DB Details: Provide the database connection details.
  • IP Address: IP address needs to be a valid IP Address.
  • Port: Enter a valid port.
  • Credential: This field is required.
  • DB Name: Name of the database to be polled for metrics
  • DB Mode: Choose the Collection Mode
  • Metrics Collection Queries: These queries are used to collect PostgreSQL server metrics.
  • Query: Enter the SQL query to execute.
  • Polling Interval [seconds]: This field is optional.
  • Collection Offset [in seconds]: Specify the delay (in seconds) from the scheduled execution time to avoid simultaneous execution of queries.
  • Custom SQL Queries: Optional.
  • Query Name: Enter a unique query name (max 63 chars; letters/numbers/_/-).
  • Query Topic: This field is required.
nan
  • PostgreSQL Log Path: Enter the full path to the PostgreSQL log file.
  • Encoding: Select the file encoding to correctly read logs that contain international characters. If no encoding is selected, plain (ASCII) will be used by default.
  • Max Bytes: The maximum number of bytes that a single log message can have. All bytes after max_bytes are discarded and not sent. This setting is especially useful for multiline log messages, which can get large. The default is 10MB (10485760).

Firewall Requirement

To collect data from this O11ySource, ensure the following ports are opened:

Source IPDestination IPDestination PortProtocolDirection
vuSmartMaps Collection/Ingress node IPIP address or FQDN of the PostgreSQL server5432TCPOutbound
IP address or FQDN of the PostgreSQL servervuSmartMaps Collection/Ingress node IP443*TCPInbound

*Before providing the firewall requirements, please update the port based on the customer environment.

Configuring the Target

Configure metrics collection from PostgreSQL Metrics from PostgreSQL are collected by establishing a JDBC connection to the server.

To get started, create a read-only vunet user with the required access on your PostgreSQL server.

Start psql on your PostgreSQL server and run:

CREATE USER vunet WITH PASSWORD '<PASSWORD>';
GRANT pg_monitor TO vunet;
GRANT pg_read_all_stats TO vunet;

To retrieve query latency statistics, enable pg_stat_statements.

Add or uncomment the following line in postgresql.conf and restart PostgreSQL:

shared_preload_libraries = 'pg_stat_statements'

Then enable the extension in the required database:

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
GRANT SELECT ON pg_stat_statements TO vunet;

Configure Log Collection from PostgreSQL PostgreSQL logs are collected using VuNet’s logs collection probe.

By default, PostgreSQL logs may go to stderr. To log into a file with useful details, update the logging section in:

  • /etc/postgresql/\<VERSION\>/main/postgresql.conf* (Linux) or
  • C:\Program Files\PostgreSQL\\<VERSION\>\data\postgresql.conf* (Windows).

Recommended parameters:

logging_collector = on
log_directory = 'pg_log'
log_filename = 'pg.log'
log_line_prefix = '%m [%p] %d %a %u %h %c'
log_file_mode = 0644
log_min_duration_statement = 0
log_timezone = 'Etc/UTC'

Configuration Steps

Metrics Collected

NameDescriptionData Type
doc_typeType of document or record.String
targetThe target system or database being referenced.String
@timestampTimestamp in string format.String
timestampTimestamp in DateTime64 format with millisecond precision.DateTime64(3)
buffers_backendTotal number of backend buffers used.UInt64
buffers_backend_diffDifference in the backend buffers since the last measurement.UInt64
buffers_checkpointTotal number of buffers written during checkpoints.UInt64
buffers_cleanTotal number of buffers cleaned.UInt64
buffers_clean_diffDifference in the cleaned buffers since the last measurement.UInt64
checkpoints_reqNumber of requested checkpoints.UInt64
checkpoints_req_diffDifference in the number of requested checkpoints since the last measurement.UInt64
checkpoints_timedNumber of timed checkpoints.UInt64
checkpoints_timed_diffDifference in the number of timed checkpoints since the last measurement.UInt64
dbName of the database.String
stateCurrent state of the system or process.String
commit_ratioThe ratio of committed transactions.Float64
formatted_sizeFormatted size (likely human-readable).String
sizeSize of the database or record in bytes.UInt64
application_nameName of the application making the request or transaction.String
backend_startStart time of the backend process.DateTime
backend_typeType of backend system (e.g., connection, service).String
process_idUnique identifier for the backend process.UInt32
querySQL query being executed.String
wait_eventEvent the process is waiting for, if any.String
wait_event_typeType of wait event.String
uptimeTime the system has been running (in seconds or milliseconds).UInt64
blks_hitNumber of blocks hit (cache hits).UInt64
blks_hit_diffDifference in the number of blocks hit since the last measurement.UInt64
blks_readNumber of blocks read from disk.UInt64
blks_read_diffDifference in the number of blocks read since the last measurement.UInt64
deadlocksNumber of deadlocks encountered.UInt32
deadlocks_diffDifference in the number of deadlocks since the last measurement.UInt32
numbackendsNumber of backend processes.UInt32
tup_deletedNumber of tuples (rows) deleted.UInt64
tup_deleted_diffDifference in the number of tuples deleted since the last measurement.UInt64
tup_fetchedThe number of tuples (rows) fetched from the database.UInt64
tup_fetched_diffThe difference in the number of tuples fetched since the last recorded value.UInt64
tup_insertedThe number of tuples inserted into the database.UInt64
tup_inserted_diffThe difference in the number of tuples inserted since the last recorded value.UInt64
tup_returnedThe number of tuples returned by the database.UInt64
tup_returned_diffThe difference in the number of tuples returned since the last recorded value.UInt64
tup_updatedThe number of tuples updated in the database.UInt64
tup_updated_diffThe difference in the number of tuples updated since the last recorded value.UInt64
xact_commitThe number of transactions committed.UInt64
xact_commit_diffThe difference in the number of transactions committed since the last recorded value.UInt64
xact_rollbackThe number of transactions rolled back.UInt64
xact_rollback_diffThe difference in the number of transactions rolled back since the last recorded value.UInt64
modeThe current mode of the database or session (e.g., read, write).String
databaseidUnique identifier of the PostgreSQL database where the long-running query is executingUInt64
usesysidInternal PostgreSQL user ID associated with the session executing the query.UInt64
databasenameName of the database.String
query_run_timeTotal duration for which the query has been runningString
query_start_timeTimestamp indicating when the query execution startedUInt64
nameType or category of operation generating the query (e.g., SQL execution).String
num_locksThe number of locks currently held in the database.UInt32
cache_hit_ratioThe ratio of cache hits to total requests, indicating the efficiency of cache usage.Float64
client_addressThe address of the client connected to the database.String
usernameThe username used to connect to the database.String
duration_msThe duration of the query or transaction in milliseconds.UInt32
pidThe process ID of the database session.UInt32
receiving_lagThe lag in data being received by the database, typically in seconds.Float64
replaying_lagThe lag in replaying WAL (Write-Ahead Logging) entries.Float64
sending_lagThe lag in data being sent from the database, typically in seconds.Float64
total_lagThe total lag across all operations in the database, typically in seconds.Float64
rows_processedThe total number of rows processed during the operation.UInt32
avg_latency_secondsThe average latency of operations, typically in seconds.Float64
max_latency_secondsThe maximum latency recorded during operations, typically in seconds.Float64
wal_size_formattedThe formatted size of the Write-Ahead Logging (WAL) data.String
wal_sizeThe size of the WAL data, typically in bytes.Float64
messageThe log message containing information about the event or error.String
timestampThe timestamp when the log entry was recorded, with millisecond precision.DateTime64(3)
log_typeThe type of log entry (e.g., error, info, warning).String
severityThe severity level of the log entry (e.g., DEBUG, INFO, WARN, ERROR).String
databaseThe name of the database associated with the log entry.String
lg_infoAdditional logging information or context relevant to the log entry.String
timezoneThe timezone in which the timestamp is recorded.String
clientThe name or identifier of the client making the database request.String
userThe username of the individual or application accessing the database.String
duration_msThe duration of the logged operation in milliseconds.Float64
process_idThe process ID associated with the logged operation.UInt32
log_levelThe log level indicating the importance of the log entry.String
statementThe SQL statement or query executed that generated the log entry.String
session_idThe unique identifier for the session during which the log entry was created.String
client_ipThe IP address of the client making the request to the database.String
bind_or_executeIndicates whether the log entry pertains to a binding or executing operation.String
statement_idA unique identifier for the statement that generated the log entry.String
hostThe hostname or identifier of the server where the database is hosted.String
targetThe target resource or operation being logged.String
DBNameAn alternative name for the database being logged, if applicable.String