Skip to main content
Version: NG-2.13

PostgreSQL

Introduction

PostgreSQL, often referred to as Postgres, 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 is tailored for all versions of PostgreSQL greater than or equal to 14.

Data Collection Method

vuSmartMaps collects PostreSQL metrics data for this O11ySource by using an internal data collector. This agent collects data based on the source configuration. Logs for PostgreSQL are collected using Logbeat agent.

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 specific Oracle deployment you want to monitor.
  • DB Details: Please provide the details of DB
  • 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 utilized for Postgresql server's metrics.
  • Query: Choose the Queries
  • Polling Interval [seconds]: How frequently data is gathered. interval should be between 180 – 86400
  • Postgres Log Path: Enter the PostgreSQL logfile's entire path

Firewall Requirement

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

Source IPDestination IPDestination PortProtocolDirection
vuSmartMaps IPIP address of the PostgreSQL server5432*TCPOutbound
IP address of the PostgreSQL servervuSmartMaps Data Collector End Point9092*TCPInbound

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

Configuring the Target

Configure Metrics Collection from PostgreSQL Server

  • To get started with the standard PostgreSQL integration, create a read-only vunet user with proper access to your PostgreSQL server.
  • Start psql on your PostgreSQL database and run:
CREATE USER vunet with password '<PASSWORD>';
GRANT pg_monitor to vunet;
GRANT pg_read_all_stats to vunet;
GRANT SELECT ON pg_stat_database to vunet;

Note: For PostgreSQL versions 9.6 and below, run the following and create a SECURITY DEFINER to read from pg_stat_activity.

CREATE FUNCTION pg_stat_activity() RETURNS SETOF pg_catalog.pg_stat_activity AS $$ SELECT * from pg_catalog.pg_stat_activity; $$
LANGUAGE sql VOLATILE SECURITY DEFINER;
CREATE VIEW pg_stat_activity_dd AS SELECT * FROM pg_stat_activity();
grant SELECT ON pg_stat_activity_dd to vunet;

Note: When generating custom metrics that require querying additional tables, you may need to grant the SELECT permission on those tables to the vunet user. Example: GRANT SELECT on to vunet;

  • To retrieve query latency statistics in PostgreSQL, ensure that the pg_stat_statements extension is enabled in your PostgreSQL configuration. If it's not enabled, you can enable it by adding or uncommenting the following line in your postgresql.conf file:
shared_preload_libraries = 'pg_stat_statements'
  • Enable the pg_stat_statements extension is not installed or enabled in your PostgreSQL database.
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
  • Then restart your PostgreSQL server. Additionally, make sure that you have the necessary permissions to access the pg_stat_statements view or extension.
GRANT SELECT ON pg_stat_statements TO vunet;

Configure Logs Collection from PostgreSQL Server

  • The logs from PostgreSQL are collected by vuSmartMaps' Logbeat agent. PostgreSQL default logging is to stderr, and logs do not include detailed information. It is recommended to log into a file with additional details specified in the log line prefix. Logging is configured within the file /etc/postgresql//main/postgresql.conf or C:\Program Files\PostgreSQL\data\postgresql.conf by default. For regular log results, please use the following parameters in the log section:
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

  • Enable the PostgreSQL O11ySource.
  • Select the Sources tab and press the + button to add PostgreSQL instance details that has to be monitored.
  • Set up metrics and log collection configurations. The O11ysource already provides predefined metric collection queries. You have the flexibility to adjust query intervals, modify existing queries, and introduce new queries as needed. Afterwards, select Save and Continue to proceed with downloading the Logbeat agent.
  • The following packages will be available for download based on the OS:Download Linux Logbeat Installation Binary - Downloads the full Logbeat Linux package with required configurations for a fresh installationDownload Linux Logbeat Update Configuration Binary - Downloads the agent configuration package to update an existing Logbeat Linux installationDownload Windows Logbeat Installation Binary - Downloads the full Logbeat Windows package with required configurations for a fresh installationDownload Windows Logbeat Update Configuration Binary - Downloads the agent configuration package to update an existing Logbeat Windows installation
  • Download the agent installation or update package, then click Finish to close the data source window.

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
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