File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM golang:1.23-alpine AS builder
2+ WORKDIR /app
3+ COPY go.mod go.sum ./
4+ RUN go mod download
5+ COPY . .
6+ RUN CGO_ENABLED=0 GOOS=linux go build -o pg-storage-visualizer ./cmd/pg-storage-visualizer
7+
8+ FROM alpine:latest
9+ RUN apk --no-cache add ca-certificates
10+ WORKDIR /app
11+ COPY --from=builder /app/pg-storage-visualizer .
12+ EXPOSE 8080
13+ ENV DATABASE_URL=postgres://postgres:postgres@db:5432/demo?sslmode=disable
14+ ENTRYPOINT ["./pg-storage-visualizer" ]
Original file line number Diff line number Diff line change @@ -27,6 +27,24 @@ make build
2727open http://localhost:8080
2828```
2929
30+ ## Docker
31+
32+ ``` bash
33+ docker-compose up --build
34+ ```
35+
36+ | Service | URL |
37+ | ------------| ------------------------------------------------------|
38+ | Visualizer | http://localhost:8080 |
39+ | PostgreSQL | ` postgres://postgres:postgres@localhost:5433/demo ` |
40+
41+ Includes demo tables (` demo ` , ` hot_demo ` ) and required extensions pre-loaded.
42+
43+ ``` bash
44+ # psql into the container
45+ docker-compose exec db psql -U postgres demo
46+ ```
47+
3048## Build Dependencies
3149
3250[ templ] ( https://templ.guide/ ) - HTML templating for Go:
Original file line number Diff line number Diff line change 1+ services :
2+ db :
3+ image : postgres:16-alpine
4+ environment :
5+ POSTGRES_USER : postgres
6+ POSTGRES_PASSWORD : postgres
7+ POSTGRES_DB : demo
8+ volumes :
9+ - ./init.sql:/docker-entrypoint-initdb.d/init.sql
10+ ports :
11+ - " 5433:5432"
12+ healthcheck :
13+ test : ["CMD-SHELL", "pg_isready -U postgres"]
14+ interval : 2s
15+ timeout : 5s
16+ retries : 10
17+
18+ app :
19+ build : .
20+ ports :
21+ - " 8080:8080"
22+ environment :
23+ DATABASE_URL : postgres://postgres:postgres@db:5432/demo?sslmode=disable
24+ depends_on :
25+ db :
26+ condition : service_healthy
Original file line number Diff line number Diff line change 1+ -- Enable required extensions
2+ CREATE EXTENSION IF NOT EXISTS pageinspect;
3+ CREATE EXTENSION IF NOT EXISTS pgstattuple;
4+
5+ -- Demo table for bloat demonstration
6+ CREATE TABLE demo (
7+ id integer PRIMARY KEY ,
8+ name text ,
9+ status text
10+ );
11+
12+ INSERT INTO demo
13+ SELECT i, ' item_' || i, ' active'
14+ FROM generate_series(1 , 50000 ) i;
15+
16+ -- HOT update demo table
17+ CREATE TABLE hot_demo (
18+ id integer PRIMARY KEY ,
19+ indexed_col text ,
20+ hot_col text
21+ );
22+
23+ CREATE INDEX ON hot_demo(indexed_col);
24+
25+ INSERT INTO hot_demo
26+ SELECT i, ' indexed_' || i, ' hot_' || i
27+ FROM generate_series(1 , 1000 ) i;
28+
29+ -- Analyze tables for accurate stats
30+ ANALYZE demo;
31+ ANALYZE hot_demo;
You can’t perform that action at this time.
0 commit comments