Skip to main content

PostgreSQL

Overview

Causely provides native integration with PostgreSQL to help you identify and resolve database performance issues before they impact your users.

Instead of just monitoring symptoms, Causely analyzes real-time signals to surface the actual root causes of database problems.

This integration helps you identify common root causes, among others:

The integration supports both self-hosted PostgreSQL instances and cloud-managed services including AWS RDS PostgreSQL, Azure Database for PostgreSQL, and Google Cloud SQL for PostgreSQL.

Setup Guide

Step 1: Create a user

Create a user for your PostgreSQL database server with the following permissions:

  • pg_read_all_stats: Required to access statistics views and performance data
  • pg_stat_statements: Required to monitor query performance (if using pg_stat_statements extension)
  • SELECT: Required to query performance metrics, table information, and schema details
  • USAGE: Required to access schema information and metadata

Step 2: Enable performance monitoring features

Enable performance monitoring features in your PostgreSQL instance to collect detailed metrics and query information. This step varies depending on your PostgreSQL deployment type, as detailed below.

Native PostgreSQL

For native PostgreSQL installations, you need to enable the pg_stat_statements extension:

  1. Edit your PostgreSQL configuration file (typically postgresql.conf)
  2. Add or update these settings:
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all
  1. Restart PostgreSQL
  2. Connect to your database and run:
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

AWS RDS PostgreSQL

Steps:

  1. Go to RDS Console → Parameter Groups
  2. Edit your parameter group
  3. Set shared_preload_libraries to include pg_stat_statements
  4. Restart your instance
  5. Connect and run: CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

Azure Database for PostgreSQL

Steps:

  1. Go to Azure Portal → PostgreSQL server
  2. Select "Server parameters"
  3. Set shared_preload_libraries to include pg_stat_statements
  4. Restart the server
  5. Connect and run: CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

Google Cloud SQL for PostgreSQL

Steps:

  1. Go to Cloud Console → Cloud SQL
  2. Edit your instance
  3. Add database flag: shared_preload_libraries=pg_stat_statements
  4. Restart the instance
  5. Connect and run: CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

Step 3: Create a Kubernetes secret for the user

After creating the user create a Kubernetes secret:

kubectl create secret generic \
--namespace causely postgres-credentials \
--from-literal=username="..." \
--from-literal=password='...' \
--from-literal=host="..." \
--from-literal=port=5432 \
--from-literal=database="..." \
--from-literal=sslmode="..."

The host must be the FQDN of your DB, or IP address if there's no DNS entry set up. It must match the FQDN/IP Causely would discover either from the K8s Server (if it's running in your K8s Cluster) or your Cloud providers API. Examples:

  • Kubernetes: host=my-postgres.namespace.service.cluster.local
  • AWS: host=myinstance.rds.amazonaws.com

If you are leveraging a proxy to connect to your database, like it's common on GCP, host must be the FQDN/IP of your proxy and additionally host_overwrite should be the IP/FQDN of the actual database service:

  • GCP: host=localhost (assuming proxy runs on the same host / Pod). host_overwrite=1.2.3.4 (the IP of your GCP Cloud SQL instance as shown in the GCP Console)

Step 4: Update Causely Configuration

Once the secret is created, update the Causely configuration to enable scraping for the new database. Below is an example configuration:

scrapers:
postgresql:
enabled: true
instances:
- secretName: postgres-credentials
namespace: causely

Alternative: Enable Credentials Autodiscovery

Causely also supports credentials autodiscovery. This feature allows you to add new scraping targets without updating the Causely configuration. Label the Kubernetes secret to enable autodiscovery for the corresponding scraper.

kubectl --namespace causely label secret postgres-credentials "causely.ai/scraper=Postgresql"

What Data is Collected

The PostgreSQL scraper collects comprehensive metadata and performance information from your PostgreSQL databases, including:

  • Database entities with names and relationships to hosting services
  • Service-to-database mappings (which service provides which database)
  • Connection details including host, port, and SSL configuration
  • Database and table schemas with complete structural information
  • Table information including names, row counts, and sizes
  • Complete table schemas with column definitions, data types, constraints, and indexes
  • Foreign key relationships and table dependencies
  • Parent-child table mappings for dependency analysis
  • Slow query analysis using PostgreSQL's pg_stat_statements
  • Lock monitoring
  • Cache and I/O performance
  • Table performance metrics