namespace: postgres groups: - name: PostgreSQL rules: - alert: PostgresqlTableNotAutoVacuumed expr: '(pg_stat_user_tables_last_autovacuum > 0) and (time() - pg_stat_user_tables_last_autovacuum) > 60 * 60 * 24 * 10' labels: severity: warning annotations: description: |- Table {{ $labels.relname }} has not been auto vacuumed for 10 days VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql table not auto vacuumed (instance {{ $labels.instance }}) - alert: PostgresqlTableNotAutoAnalyzed expr: '(pg_stat_user_tables_last_autoanalyze > 0) and (time() - pg_stat_user_tables_last_autoanalyze) > 24 * 60 * 60 * 10' labels: severity: warning annotations: description: |- Table {{ $labels.relname }} has not been auto analyzed for 10 days VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql table not auto analyzed (instance {{ $labels.instance }}) - alert: PostgresqlDeadLocks expr: 'increase(pg_stat_database_deadlocks{datname!~"template.*|postgres"}[1m]) > 5' labels: severity: warning annotations: description: |- PostgreSQL has dead-locks VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql dead locks (instance {{ $labels.instance }}) - alert: PostgresqlHighRollbackRate expr: 'sum by (namespace, datname) ((rate(pg_stat_database_xact_rollback{datid!="0",datname!~"template.*|postgres"}[3m])) / ((rate(pg_stat_database_xact_rollback{datid!="0",datname!~"template.*|postgres"}[3m])) + (rate(pg_stat_database_xact_commit{datid!="0",datname!~"template.*|postgres"}[3m])))) > 0.02' labels: severity: warning annotations: description: |- Ratio of transactions being aborted compared to committed is > 2 % VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql high rollback rate (instance {{ $labels.instance }}) - alert: PostgresqlHighRateStatementTimeout expr: 'rate(postgresql_errors_total{type="statement_timeout"}[1m]) > 3' labels: severity: critical annotations: description: |- Postgres transactions showing high rate of statement timeouts VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql high rate statement timeout (instance {{ $labels.instance }}) - alert: PostgresqlHighRateDeadlock expr: 'increase(postgresql_errors_total{type="deadlock_detected"}[1m]) > 1' labels: severity: critical annotations: description: |- Postgres detected deadlocks VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql high rate deadlock (instance {{ $labels.instance }}) - alert: PostgresqlTooManyDeadTuples expr: '((pg_stat_user_tables_n_dead_tup > 10000) / (pg_stat_user_tables_n_live_tup + pg_stat_user_tables_n_dead_tup)) >= 0.1' for: 2m labels: severity: warning annotations: description: |- PostgreSQL dead tuples is too large VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql too many dead tuples (instance {{ $labels.instance }}) - alert: PostgresqlTooManyLocksAcquired expr: '((sum(pg_locks_count)) / (pg_settings_max_locks_per_transaction * pg_settings_max_connections)) > 0.2' for: 2m labels: severity: critical annotations: description: |- Too many locks acquired on the database. If this alert happens frequently, we may need to increase the postgres setting max_locks_per_transaction. VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql too many locks acquired (instance {{ $labels.instance }}) - alert: PostgresqlBloatIndexHigh(>80%) expr: 'pg_bloat_btree_bloat_pct > 80 and on (idxname) (pg_bloat_btree_real_size > 1e+08)' for: 1h labels: severity: warning annotations: description: |- The index {{ $labels.idxname }} is bloated. You should execute `REINDEX INDEX CONCURRENTLY {{ $labels.idxname }};` VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql bloat index high (> 80%) (instance {{ $labels.instance }}) - alert: PostgresqlBloatTableHigh(>80%) expr: 'pg_bloat_table_bloat_pct > 80 and on (relname) (pg_bloat_table_real_size > 2e+08)' for: 1h labels: severity: warning annotations: description: |- The table {{ $labels.relname }} is bloated. You should execute `VACUUM {{ $labels.relname }};` VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql bloat table high (> 80%) (instance {{ $labels.instance }}) - alert: PostgresqlInvalidIndex expr: 'pg_genaral_index_info_pg_relation_size{indexrelname=~".*ccnew.*"}' for: 6h labels: severity: warning annotations: description: |- The table {{ $labels.relname }} has an invalid index: {{ $labels.indexrelname }}. You should execute `DROP INDEX {{ $labels.indexrelname }};` VALUE = {{ $value }} LABELS = {{ $labels }} summary: Postgresql invalid index (instance {{ $labels.instance }})