Skip to content

Commit 17c54fd

Browse files
author
Dementii Priadko
committed
Merge branch 'checkup20' into 'main'
Checkup20 See merge request postgres-ai/postgres_ai!27
2 parents c00e7b4 + da13098 commit 17c54fd

File tree

3 files changed

+48
-58
lines changed

3 files changed

+48
-58
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,35 @@ A complete PostgreSQL monitoring solution with automated performance analysis an
44

55
## 📋 Requirements
66

7+
**Infrastructure:**
8+
- **Linux machine** with Docker installed (separate from your database server)
9+
- **Docker access** - the user running `postgres_ai` must have Docker permissions
10+
- **Network access** to the PostgreSQL database(s) you want to monitor
11+
12+
**Database:**
713
- Supports PostgreSQL versions 14-17
814

15+
## ⚠️ Security Notice
16+
17+
**WARNING: Security is your responsibility!**
18+
19+
This monitoring solution exposes several ports that **MUST** be properly firewalled:
20+
- **Port 3000** (Grafana) - Contains sensitive database metrics and dashboards
21+
- **Port 58080** (PGWatch Postgres) - Database monitoring interface
22+
- **Port 58089** (PGWatch Prometheus) - Database monitoring interface
23+
- **Port 59090** (Prometheus) - Metrics storage and queries
24+
- **Port 59091** (PGWatch Prometheus endpoint) - Metrics collection
25+
- **Port 55000** (Flask API) - Backend API service
26+
- **Port 55432** (Demo DB) - When using `--demo` option
27+
- **Port 55433** (Metrics DB) - PostgreSQL metrics storage
28+
29+
**Configure your firewall to:**
30+
- Block public access to all monitoring ports
31+
- Allow access only from trusted networks/IPs
32+
- Use VPN or SSH tunnels for remote access
33+
34+
Failure to secure these ports may expose sensitive database information!
35+
936
## 🚀 Quick start
1037

1138
Create a new DB user in database to be monitored (skip this if you want just to check out `postgres_ai` monitoring with a synthetic `demo` database):

config/pgwatch-prometheus/metrics.yml

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -311,57 +311,8 @@ metrics:
311311
pg_stat_database, pg_control_system()
312312
where
313313
datname = current_database()
314-
17: |-
315-
select /* pgwatch_generated */
316-
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
317-
current_database() as tag_datname,
318-
numbackends,
319-
xact_commit,
320-
xact_rollback,
321-
blks_read,
322-
blks_hit,
323-
tup_returned,
324-
tup_fetched,
325-
tup_inserted,
326-
tup_updated,
327-
tup_deleted,
328-
conflicts,
329-
temp_files,
330-
temp_bytes,
331-
deadlocks,
332-
shared_blk_read_time as blk_read_time,
333-
shared_blk_write_time as blk_write_time,
334-
extract(epoch from (now() - pg_postmaster_start_time()))::int8 as postmaster_uptime_s,
335-
checksum_failures,
336-
extract(epoch from (now() - checksum_last_failure))::int8 as checksum_last_failure_s,
337-
case when pg_is_in_recovery() then 1 else 0 end as in_recovery_int,
338-
system_identifier::text as tag_sys_id,
339-
session_time::int8,
340-
active_time::int8,
341-
idle_in_transaction_time::int8,
342-
sessions,
343-
sessions_abandoned,
344-
sessions_fatal,
345-
sessions_killed,
346-
(select count(*) from pg_index i
347-
where not indisvalid
348-
and not exists ( /* leave out ones that are being actively rebuilt */
349-
select * from pg_locks l
350-
join pg_stat_activity a using (pid)
351-
where l.relation = i.indexrelid
352-
and a.state = 'active'
353-
and a.query ~* 'concurrently'
354-
)) as invalid_indexes
355-
from
356-
pg_stat_database, pg_control_system()
357-
where
358-
datname = current_database()
359314
gauges:
360-
- numbackends
361-
- postmaster_uptime_s
362-
- backup_duration_s
363-
- backup_duration_s
364-
- checksum_last_failure_s
315+
- '*'
365316
locks_mode:
366317
description: >
367318
Retrieves lock mode statistics from the PostgreSQL `pg_locks` view, providing insights into the different lock modes currently held in the database.

postgres_ai

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,28 @@ check_docker_running() {
200200
log_info "Checking Docker daemon status..."
201201

202202
if ! docker info &> /dev/null; then
203-
log_error "Docker daemon is not running"
203+
log_error "Cannot access Docker daemon"
204204
echo
205-
echo "Please start Docker:"
206-
echo " macOS: Start Docker Desktop application"
207-
echo " Linux: sudo systemctl start docker"
208-
echo " Windows: Start Docker Desktop application"
205+
echo "This could be due to:"
206+
echo " 1. Docker daemon not running"
207+
echo " 2. User lacks permission to access Docker"
208+
echo
209+
echo "Solutions:"
210+
echo " If Docker daemon is not running:"
211+
echo " • macOS: Start Docker Desktop application"
212+
echo " • Linux: sudo systemctl start docker"
213+
echo " • Windows: Start Docker Desktop application"
214+
echo
215+
echo " If permission denied:"
216+
echo " • Linux: Add user to docker group: sudo usermod -aG docker \$USER"
217+
echo " • Then log out and back in, or run: newgrp docker"
218+
echo " • Verify with: docker run hello-world"
219+
echo
220+
echo " Alternative: Run postgres_ai with sudo (not recommended)"
209221
exit 1
210222
fi
211223

212-
log_success "Docker daemon is running"
224+
log_success "Docker daemon is accessible"
213225
}
214226

215227
# Check system resources
@@ -894,12 +906,12 @@ start_services() {
894906

895907
if is_demo_mode; then
896908
log_info "Starting Postgres AI services (demo mode - including target database)..."
897-
$compose_cmd -f "$COMPOSE_FILE" up -d --build
909+
$compose_cmd -f "$COMPOSE_FILE" up -d
898910
else
899911
log_info "Starting Postgres AI monitoring services (production mode)..."
900912
log_info "Target demo database not included - add your own PostgreSQL instances to monitor"
901913
# Start all services except target-db
902-
$compose_cmd -f "$COMPOSE_FILE" up -d sources-generator sink-postgres sink-prometheus pgwatch-postgres pgwatch-prometheus grafana flask-backend postgres-reports --build
914+
$compose_cmd -f "$COMPOSE_FILE" up -d sources-generator sink-postgres sink-prometheus pgwatch-postgres pgwatch-prometheus grafana flask-backend postgres-reports
903915
fi
904916

905917
log_success "Services started!"

0 commit comments

Comments
 (0)