PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance.
Prerequisites
- Create a read-only user with proper access to your PostgreSQL server and start psql on your PostgreSQL database.
- For PostgreSQL version 10 and above, run the following:
create user '<Username>' with password '<PASSWORD>'; grant pg_monitor to <Username>;
- For older versions of PostgreSQL, run the following:
create user '<Username>' with password '<PASSWORD>'; grant SELECT ON pg_stat_database to '<Username>';
- To get the metrics of WAL files, grant the folllowing permissions:
REVOKE ALL ON FUNCTION pg_ls_dir(dirname text ) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_ls_dir(dirname text ) TO '<Username>';
- To get the metric of Function:
vi /etc/postgresql/12/main/postgresql.conf
track_functions = all
Note: Do not restart the server for this setting.
- For Virtual Machines, install the Linux Agent.
Configuring the credentials
Configure the credentials in the directory /opt/opsramp/agent/conf/app.d/creds.yaml
postgresql:
- name: postgresql
user: <username>
pwd: <Password>
encoding-type: plain
labels:
key1: val1
key2: val2
Configuring the application
Virtual machine
Configure the application in the directory /opt/opsramp/agent/conf/app/discovery/auto-detection.yaml
- name: postgresql
instance-checks:
service-check:
- postgresql
port-check:
- 5432
# monitoring-configs :
# # The name of the PostgresSQL database to monitor.
# # Note: If omitted, the default system Postgres database is queried.
# dbname: $DBNAME
# # ssl type could be any of these : disable , allow, prefer, require, verify-ca, verify-full
# ssl: disable
# # The list of relations/tables must be specified here to track per-relation (table) metrics.
# # If enabled, `dbname` should be specified to collect database-specific relations metrics.
# # You can either specify a single relation by its exact name in 'relation_name' or use a regex to track metrics in relation_regex
# # By default all schemas are included. To track relations from specific schemas only,
# # you can specify the `schemas` attribute and provide a list of schemas to use for filtering.
# relations:
# - relation_name: $TABLE_NAME1
# schemas:
# - $SCHEMA_NAME1
# - relation_name: $TABLE_NAME2
# schemas:
# - $SCHEMA_NAME1
# - $SCHEMA_NAME2
# - relation_regex: $TABLE_PATTERN1
# schemas:
# - $SCHEMA_NAME1
# - $SCHEMA_NAME2
Docker environment
Configure the application in the directory /opt/opsramp/agent/conf/app/discovery/auto-container-detection.yaml
- name: postgresql
container-checks:
image-check:
- postgres
port-check:
- 5432
# monitoring-configs :
# # The name of the PostgresSQL database to monitor.
# # Note: If omitted, the default system Postgres database is queried.
# dbname: $DBNAME
# # ssl type could be any of these : disable , allow, prefer, require, verify-ca, verify-full
# ssl: disable
# # The list of relations/tables must be specified here to track per-relation (table) metrics.
# # If enabled, `dbname` should be specified to collect database-specific relations metrics.
# # You can either specify a single relation by its exact name in 'relation_name' or use a regex to track metrics in relation_regex
# # By default all schemas are included. To track relations from specific schemas only,
# # you can specify the `schemas` attribute and provide a list of schemas to use for filtering.
# relations:
# - relation_name: $TABLE_NAME1
# schemas:
# - $SCHEMA_NAME1
# - relation_name: $TABLE_NAME2
# schemas:
# - $SCHEMA_NAME1
# - $SCHEMA_NAME2
# - relation_regex: $TABLE_PATTERN1
# schemas:
# - $SCHEMA_NAME1
# - $SCHEMA_NAME2
Kubernetes environment
Configure the application in config.yaml
- name: postgresql
container-checks:
image-check:
- postgres
port-check:
- 5432
# monitoring-configs :
# # The name of the PostgresSQL database to monitor.
# # Note: If omitted, the default system Postgres database is queried.
# dbname: $DBNAME
# # ssl type could be any of these : disable , allow, prefer, require, verify-ca, verify-full
# ssl: disable
# # The list of relations/tables must be specified here to track per-relation (table) metrics.
# # If enabled, `dbname` should be specified to collect database-specific relations metrics.
# # You can either specify a single relation by its exact name in 'relation_name' or use a regex to track metrics in relation_regex
# # By default all schemas are included. To track relations from specific schemas only,
# # you can specify the `schemas` attribute and provide a list of schemas to use for filtering.
# relations:
# - relation_name: $TABLE_NAME1
# schemas:
# - $SCHEMA_NAME1
# - relation_name: $TABLE_NAME2
# schemas:
# - $SCHEMA_NAME1
# - $SCHEMA_NAME2
# - relation_regex: $TABLE_PATTERN1
# schemas:
# - $SCHEMA_NAME1
# - $SCHEMA_NAME2
Validate
Go to Resources under the Infrastructure tab to check if your resources are onboarded and the metrics are collected.
Metrics
OpsRamp Metric | Metric Display Name | Unit | Description |
---|---|---|---|
postgresql_autovac_freeze | Autovac Freeze | percent | Provides the percentage of current transactions to the maximum freeze number |
postgresql_ping | Ping | microseconds | Provides the Ping response time of PostgreSQL database |
postgresql_bloat | Bloat | Bloat | Checks the amount of bloat in tables and indexes |
postgresql_conn_idle_tnx | Connections Idle Tnx | connections | Checks the number of connections 'idle in transaction' state |
postgresql_conn_idle | Connections Idle | connections | Checks number of connections idle in given state |
postgresql_conn_total | Connections Total | connections | Checks total number of connections in given state |
postgresql_conn_running | Connections Running | connections | Checks number of connections running in given state |
postgresql_conn_waiting | Connections Waiting | connections | Checks number of connections waiting in given state |
postgresql_tnxage_idle_tnx | Tnxage IdleTnx | Idle Tnx Age | Checks the number and duration of 'idle in transaction' queries on one or more databases |
postgresql_tnxage_running | Tnxage Running | Idle Tnx Running | Checks the number and duration of 'running transaction' queries on one or more databases |
postgresql_wal | Wal | Files | Checks how many WAL files exist in the pg_wal directory |
postgresql_locks | Locks | Locks | Number of locks active for this database |
postgresql_locks_granted | Locks Granted | Locks | Number of granted locks active for this database |
postgresql_locks_not_granted | Locks Not Granted | Locks | Number of not granted locks active for this database |
postgresql_commits | Commits | Transactions / second | Number of transactions in this database that have been committed |
postgresql_rollbacks | Rollbacks | Transactions / second | Number of transactions in this database that have been rolled back |
postgresql_disk_read | Disk Reads | Blocks / second | Number of disk blocks read in this database |
postgresql_buffer_hit | Buffer Hits | Hits / second | Number of times disk blocks were found in the buffer cache, preventing the need to read from the database |
postgresql_rows_returned | Rows Returned | Rows / second | Number of rows returned by queries in this database |
postgresql_rows_fetched | Rows Fetched | Rows / second | Number of rows fetched by queries in this database |
postgresql_rows_inserted | Rows Inserted | Rows / second | Number of rows inserted by queries in this database |
postgresql_rows_updated | Rows Updated | Rows / second | Number of rows updated by queries in this database |
postgresql_rows_deleted | Rows Deleted | Rows / second | Number of rows deleted by queries in this database |
postgresql_database_size | Database Size | MegaBytes | Disk space used by this database |
postgresql_buffer_clear | Buffer Clear | Clear Buffers | Checks number of buffer which have clear page in the shared cache |
postgresql_buffer_dirty | Buffer Dirty | Dirty Buffers | Checks number of buffer which have dirty page in the shared cache |
postgresql_buffer_used | Buffer Used | Used Buffers | Checks number of buffer used in the shared cache |
postgresql_buffer_total | Buffer Total | Total Buffers | Checks total number of buffer in the shared cache |
postgresql_temp_files | Temp Files | Files / second | Number of temporary files created by queries in this database. |
postgresql_connections | connections | connections | Number of active connections to this database |
postgresql_before_xid_wraparound | Before Xid Wraparound | Transactions | Number of transactions that can occur until a transaction wraparound |
postgresql_deadlocks | Deadlocks | Deadlocks / second | Number of deadlocks detected in this database |
postgresql_temp_bytes | Temp Bytes | bytes / second | Amount of data written to temporary files by queries in this database |
postgresql_bgwriter_checkpoints_timed | Bgwriter Checkpoints Timed | Checkpoints | Number of scheduled checkpoints that have been performed |
postgresql_bgwriter_checkpoints_requested | Bgwriter Checkpoints Requested | Checkpoints | Number of requested checkpoints that have been performed |
postgresql_bgwriter_buffers_checkpoint | Bgwriter Buffers Checkpoint | Buffers | Number of buffers written during checkpoints |
postgresql_bgwriter_buffers_clean | Bgwriter Buffers Clean | Buffers | Number of buffers written by the background writer |
postgresql_bgwriter_maxwritten_clean | Bgwriter Maxwritten Clean | Count | Number of times the background writer stopped a cleaning scan because it had written too many buffers |
postgresql_bgwriter_buffers_backend | Bgwriter Buffers Backend | Buffers | Number of buffers written directly by a backend |
postgresql_bgwriter_buffers_alloc | Bgwriter Buffers Alloc | Buffers | Number of buffers allocated |
postgresql_bgwriter_buffers_backend_fsync | Bgwriter Buffers Backend Fsync | Count | Number of times a backend had to execute its own fsync call instead of the background writer. |
postgresql_bgwriter_write_time | Bgwriter Write Time | milliseconds | Total amount of checkpoint processing time spent writing files to disk |
postgresql_bgwriter_sync_time | Bgwriter Sync Time | milliseconds | Total amount of checkpoint processing time spent synchronizing files to disk |
postgresql_seq_scans | Seq Scans | Scans / second | Number of sequential scans initiated on this table |
postgresql_seq_rows_read | Seq Rows Read | Rows / second | Number of live rows fetched by sequential scans |
postgresql_index_scans | Index Scans | Scans / second | Number of index scans initiated on this table |
postgresql_index_rel_rows_fetched | Index Rel Rows Fetched | Rows / second | Number of live rows fetched by index scans |
postgresql_index_rows_fetched | Index Rows Fetched | Rows / second | Number of live rows fetched by index scans |
postgresql_rows_hot_updated | Rows Hot Updated | Row / second | Number of rows HOT updated (that is, with no separate index update required) |
postgresql_live_rows | Live Rows | Rows | Estimated number of live rows |
postgresql_dead_rows | Dead Rows | Rows | Estimated number of dead rows |
postgresql_rows_inserted_table_stat | Rows Inserted Table Stat | Rows / second | Number of rows inserted |
postgresql_rows_updated_table_stat | Rows Updated Table Stat | Rows / second | Number of rows updated (includes HOT updated rows) |
postgresql_rows_deleted_table_stat | Rows Deleted Table Stat | Rows / second | Number of rows deleted |
postgresql_heap_blocks_read | Heap Blocks Read | Blocks / second | Number of disk blocks read from this table |
postgresql_heap_blocks_hit | Heap Blocks Hit | Hits / second | Number of buffer hits in this table |
postgresql_index_blocks_read | Index Blocks Read | Blocks / second | Number of disk blocks read from all indexes on this table |
postgresql_index_blocks_hit | Index Blocks Hit | Hits / second | Number of buffer hits in all indexes on this table |
postgresql_toast_blocks_read | Toast Blocks Read | Blocks / second | Number of disk blocks read from this table's TOAST table (if any) |
postgresql_toast_blocks_hit | Toast Blocks Hit | Hits / second | Number of buffer hits in this table's TOAST table (if any) |
postgresql_toast_index_blocks_read | Toast Index Blocks Read | Blocks / second | Number of disk blocks read from this table's TOAST table indexes (if any) |
postgresql_toast_index_blocks_hit | Toast Index Blocks Hit | Blocks / second | Number of buffer hits in this table's TOAST table indexes (if any) |
postgresql_table_size | Table Size | bytes | Total disk space used by the specified table. Includes TOAST, free space map, and visibility map. Excludes indexes. |
postgresql_index_size | Index Size | bytes | Total disk space used by indexes attached to the specified table |
postgresql_total_size | Total Size | bytes | Total disk space used by the table, including indexes and TOAST data |
postgresql_index_stat_index_scans | Index Stat Index Scans | Scans / second | Number of index scans initiated on this index |
postgresql_index_rows_read | Index Rows Read | Rows / second | Number of index entries returned by scans on this index |
postgresql_index_stat_index_rows_fetched | Index Stat Index Rows Fetched | Rows / second | Number of live table rows fetched by simple index scans using this index |
postgresql_archiver_archived_count | Archiver Archived Count | Files | Number of WAL files that have been successfully archived |
postgresql_archiver_failed_count | Archiver Failed Count | Failed Attempts | Number of failed attempts for archiving WAL files |
postgresql_table_count | Table Count | Tables | Number of user tables in this database |
postgresql_function_calls | Function Calls | Calls / second | Number of times this function has been called |
postgresql_function_total_time | Function Total Time | MilliSecond / second | Total time spent in this function and all other functions called by it |
postgresql_function_self_time | Function Self Time | MilliSecond / second | Total time spent in this function itself, not including other functions called by it |
postgresql_replication_delay | Replication Delay | seconds | Current replication delay. Only available with postgresql 9.1 and newer |
postgresql_replication_delay_bytes | Replication Delay Bytes | bytes | Current replication delay. Only available with postgresql 9.2 and newer |
postgresql_percent_usage_connections | Percent Usage Connections | Fraction | Number of connections to this database as a fraction of the maximum number of allowed connections |
postgresql_max_connections | Max Connections | connections | Maximum number of client connections allowed to this database |
postgresql_transactions_open | Transactions Open | Transactions | Number of open transactions in this database |
postgresql_transactions_idle_in_transaction | Transactions Idle In Transaction | Transactions | Number of 'idle in transaction' transactions in this database |
postgresql_active_queries | Active Queries | Queries | Number of active queries in this database |
postgresql_waiting_queries | Waiting Queries | Queries | Number of waiting queries in this database |