This guide explains how to use the proxy's multi-database feature with random session credentials.
The proxy now supports 4 pre-configured databases that you can choose from when starting the proxy. Each session gets unique random credentials that expire when the proxy stops.
Main production database with test data.
Tables:
test_data- Simple test records with id, name, value, created_at
Use Cases:
- Basic CRUD operations
- Testing aggregate functions
- Simple SELECT/INSERT/UPDATE queries
Test Queries: test-queries/postgres.sql
User and content management system.
Tables:
users- User accounts (id, username, email, created_at)posts- User posts (id, user_id, title, content, created_at)
Use Cases:
- JOIN operations
- User activity tracking
- Content management queries
Test Queries: test-queries/mydb.sql
Analytics and event tracking database.
Tables:
events- Event logs (id, event_name, event_type, user_id, metadata JSONB, created_at)metrics- Performance metrics (id, metric_name, metric_value, recorded_at)
Use Cases:
- JSONB queries
- Event tracking
- Analytics aggregations
- Time-series data
Test Queries: test-queries/analytics_db.sql
E-commerce staging environment.
Tables:
products- Product catalog (id, product_name, category, price, stock, created_at)orders- Order records (id, product_id, quantity, total_price, status, created_at)
Use Cases:
- E-commerce queries
- Inventory management
- Revenue calculations
- Order tracking
Test Queries: test-queries/staging_db.sql
# Start PostgreSQL container
make db-up
# Initialize all 4 databases with test data
make db-initThis creates and populates all 4 databases.
make proxyYou'll see an interactive menu:
╔═══════════════════════════════════════════════════╗
║ Database Proxy - Session Recorder ║
║ Intercept & Monitor DB ║
╚═══════════════════════════════════════════════════╝
🗄️ Select Database to Monitor:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│ 1) Production DB
│ Main production database (postgres)
│ Database: postgres
├──────────────────────────────────────────────────
│ 2) User Management
│ User and posts database (mydb)
│ Database: mydb
├──────────────────────────────────────────────────
│ 3) Analytics
│ Analytics and events database (analytics_db)
│ Database: analytics_db
├──────────────────────────────────────────────────
│ 4) Staging
│ Staging environment (staging_db)
│ Database: staging_db
└──────────────────────────────────────────────────
Select a database [1-4]:
Type a number (1-4) and press Enter. For example, type 2 to select User Management.
After selecting, you'll see unique session credentials:
✅ Selected: User Management
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📋 Session Credentials (Valid for this session only):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Database: User Management
Session User: session_a3f2c8d1
Password: (any password works)
Target DB: mydb
→ Maps to: postgres://postgres:***@localhost:5432/mydb
🔌 Connect using:
psql -h localhost -p 5433 -U session_a3f2c8d1 -d mydb
Or with connection string:
postgres://session_a3f2c8d1:anypassword@localhost:5433/mydb
🔍 Monitoring all queries and responses...
💡 Tip: Session credentials change each time you run the proxy
Important:
- The
session_a3f2c8d1username is random and changes each time - These credentials are only valid for this proxy session
- When you restart the proxy, you'll get new credentials
Open a new terminal and connect using the displayed credentials:
# Using the session user shown above
psql -h localhost -p 5433 -U session_a3f2c8d1 -d mydbOr run test queries:
psql -h localhost -p 5433 -U session_a3f2c8d1 -d mydb -f test-queries/mydb.sql- Security: Each session gets unique credentials that can't be reused
- Tracking: Easy to identify which session executed which queries
- Isolation: Multiple proxy instances can run simultaneously without conflicts
- Audit: Session files are named with the session user and timestamp
Session usernames follow the pattern:
session_<8_hex_chars>
Example: session_a3f2c8d1, session_7b9c4e2f
When you connect and run queries, a JSON file is created:
sessions/session_a3f2c8d1_2025-10-08_14-30-45.json
This file contains all queries and results from that session.
# Terminal 1: Start proxy and select User Management (option 2)
make proxy
# Terminal 2: Connect with displayed credentials
psql -h localhost -p 5433 -U session_XXXXXXXX -d mydb
# Run some queries
SELECT * FROM users;
SELECT * FROM posts JOIN users ON posts.user_id = users.id;# Terminal 1: Start proxy and select Analytics (option 3)
make proxy
# Terminal 2: Run analytics test queries
psql -h localhost -p 5433 -U session_XXXXXXXX -d analytics_db -f test-queries/analytics_db.sql# Session 1: Test against User Management
make proxy # Select option 2
# ... run queries ...
# Ctrl+C to stop
# Session 2: Test against Staging
make proxy # Select option 4
# ... run queries ...
# Ctrl+C to stop
# Now replay and compare both sessions
make replay # Select session to replayAfter running queries, you can replay any session:
make replayStep 1: Select Session
The tool shows all recorded sessions:
╔═══════════════════════════════════════════════════╗
║ Session Replay Tool ║
║ Re-execute recorded queries ║
╚═══════════════════════════════════════════════════╝
📂 Available Session Files:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│ 1) session_a3f2c8d1_2025-10-08_14-30-45.json
│ User: session_a3f2c8d1
│ Date: 2025-10-08 14:30:45
│ Size: 2.4 KB
├──────────────────────────────────────────────────
│ 2) session_7b9c4e2f_2025-10-08_13-15-20.json
│ User: session_7b9c4e2f
│ Date: 2025-10-08 13:15:20
│ Size: 3.1 KB
└──────────────────────────────────────────────────
Select a session to replay [1-2] or 'q' to quit: 1
Step 2: Enter Database URL
You'll be prompted to specify which database to replay against:
🗄️ Database Connection
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Examples:
postgres://postgres:postgres@localhost:5432/postgres
postgres://postgres:postgres@localhost:5432/mydb
postgres://postgres:postgres@localhost:5432/analytics_db
postgres://postgres:postgres@localhost:5432/staging_db
Enter database URL: postgres://postgres:postgres@localhost:5432/mydb
Why specify the database?
- You can replay sessions against different databases for testing
- Useful for validating migrations or schema changes
- Allows testing same queries across production/staging/dev environments
Keep track of which database you're testing and why:
- Use session files to review test results later
- Name your test scenarios in comments
You can run multiple proxy instances on different ports:
# Edit main.go to use different port, or
# Connect multiple clients to the same proxy session# Remove old session files
rm sessions/*.json
# Or keep for audit trail# Reset databases to initial state
make db-down
make db-up
make db-init
# View database directly (bypass proxy)
make db-connectProblem: Connection refused or authentication failed
Solution:
- Make sure the proxy is running
- Use the exact username shown in the proxy output
- Copy-paste the connection string to avoid typos
- Try any password - it's ignored
Problem: Database "mydb" does not exist
Solution:
# Reinitialize databases
make db-initProblem: Old session credentials don't work
Solution:
- This is expected! Session credentials change on each proxy start
- Always use the credentials displayed in the current proxy session
- Explore each database with the provided test queries
- Try writing your own complex queries
- Record sessions and replay them for validation
- Integrate into your testing workflow
For more information, see:
- README.md - Main documentation
- EXAMPLE_WORKFLOW.md - Complete workflow example
- Test query files in
test-queries/directory