CLI installation
The fastest way to get PostgresAI monitoring running locally.
Prerequisites
- Node.js 18+ or Bun 1.0+
- Docker 20.10+
- PostgreSQL 14 through 19 with
pg_stat_statements(see supported Postgres versions)
Bun support
All commands work with both npx and bunx. The CLI is written in TypeScript and runs natively on Bun.
Step 1: Prepare target database
Before starting the monitoring stack, configure your PostgreSQL instance:
PGPASSWORD=your_password npx postgresai@latest prepare-db "postgresql://postgres@localhost:5432/mydb"
What prepare-db does
- Enables pg_stat_statements extension
- Creates monitoring user (
postgres_ai_monby default) with minimal read-only privileges - Validates configuration for optimal monitoring
prepare-db options
npx postgresai@latest prepare-db [connection] [options]
Options:
--monitoring-user <name> Monitoring username (default: postgres_ai_mon)
--password <pass> Monitoring password (auto-generated if not set)
--skip-optional-permissions Skip optional permissions for managed providers
--print-sql Print SQL instead of executing it
--verify Verify monitoring permissions after setup
Example output
✓ Connected to PostgreSQL 16.2
✓ pg_stat_statements extension enabled
✓ Created monitoring user 'postgres_ai_mon'
✓ Granted required permissions
Monitoring connection string:
postgresql://postgres_ai_mon:auto_generated_pass@localhost:5432/mydb