Basira Docs

PostgreSQL Setup

Configure PostgreSQL for Basira monitoring.

Basira requires a dedicated database user with read access to performance views and the pg_stat_statements and auto_explain extensions enabled.

1. Create Monitoring User

Connect to your PostgreSQL instance as a superuser and run:

CREATE USER basira_monitor WITH PASSWORD 'your-secure-password';
GRANT pg_monitor TO basira_monitor;

The pg_monitor role (available in PostgreSQL 10+) grants read access to pg_stat_activity, pg_stat_statements, and other system views.

2. Enable pg_stat_statements

pg_stat_statements tracks query execution statistics. Add it to your postgresql.conf:

shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.track = all
pg_stat_statements.max = 10000

Then restart PostgreSQL and create the extension:

CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

Verify

SELECT count(*) FROM pg_stat_statements;

3. Enable auto_explain

auto_explain logs execution plans for slow queries. Add to postgresql.conf:

shared_preload_libraries = 'pg_stat_statements,auto_explain'
auto_explain.log_min_duration = 100   # log queries slower than 100ms
auto_explain.log_analyze = on
auto_explain.log_format = json
auto_explain.log_nested_statements = on

Restart PostgreSQL after making changes.

Verify

Run a slow query and check the PostgreSQL logs for auto_explain output.

4. Network Access

Ensure the Basira agent can reach your PostgreSQL instance:

  • Direct connection: Allow the agent's IP in pg_hba.conf
  • Cloud providers: Add the agent's security group/VPC to your database's allowed connections
  • SSL: We recommend sslmode=require at minimum

Next Steps

Once your database is configured, install the Basira agent and point it at your PostgreSQL instance.

On this page