┌─────────────────────────────────────────────────────────────────┐
│ │
│ 🔍 P G P E E K │
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ │
│ │
│ 📊 Connect • 🔍 Browse • ⚡ Query │
│ │
│ Database exploration that doesn't suck │
│ No complex setup, no bullshit - just peek into your data │
│ │
└─────────────────────────────────────────────────────────────────┘
peek into postgres without the hassle
- Zero ceremony - One command to peek into any database
- Beautiful TUI - Navigate schemas, tables, and data with ease
- Natural queries - Type what you mean, get what you want
- No setup hell - Add connections with simple URLs
- Fast exploration - Instantly browse schemas, tables, and sample data
cargo install pgpeek# Initialize pgpeek
pgpeek init
# Add your database
pgpeek add local postgres://user:pass@localhost:5432/mydb --default
# Start exploring
pgpeek exploreWhen you run pgpeek without arguments, you'll see:
🔍 pgpeek
┌─────────────────────────────────────────┐
│ Database exploration that doesn't suck │
└─────────────────────────────────────────┘
📊 Connect • 🔍 Browse • ⚡ Query
Quick start:
• pgpeek init → setup config
• pgpeek add <name> <url> → add database
• pgpeek explore → start explorer
When starting the explorer:
┌─ 🔍 pgpeek explorer ─┐
│ │
│ 🚀 Connecting to: │
│ mydb │
│ │
│ ⏳ Loading schemas │
└──────────────────────┘
⠋ Connecting to database...
✓ Connected successfully!
Inside the TUI, you'll see a clean interface:
┌─────────────────────── 🔍 pgpeek ────────────────────────┐
│ 📊 local → postgres://user@localhost:5432/mydb │
└──────────────────────────────────────────────────────────┘
┌── 📈 Database Overview ────────────────────────────────┐
│ Database: mydb │
│ Size: 125 MB │
│ Tables: 47 │
│ Schemas: 3 │
│ User: postgres │
└────────────────────────────────────────────────────────┘
┌─── 📂 Schemas ─────────────────────────────────────────┐
│ ▶ 📁 public (34 tables) │
│ 📁 auth (8 tables) │
│ 📁 analytics (5 tables) │
└────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────┐
│ Status: Database overview loaded - 3 schemas │
│ Help: 1=Overview 2=Schemas 3=Tables 4=Query q=Quit │
└────────────────────────────────────────────────────────┘
# Add connections
pgpeek add prod postgres://user:pass@prod-db.com:5432/app
pgpeek add staging postgres://user:pass@staging.com:5432/app_staging
# List all connections
pgpeek list
# Test a connection
pgpeek test prod
# Remove a connection
pgpeek remove old_db# Start the interactive explorer
pgpeek explore # uses default connection
pgpeek explore prod # use specific connectionOnce the explorer opens, you can navigate with these controls:
Main Navigation (available anywhere):
1- Database overview (size, table count, connection info)2- Browse schemas (list all schemas with table counts)3- Browse all tables (across all schemas or within selected schema)4- Open SQL query editor5- Saved queries (manage your stored queries)r- Refresh current view/dataq- Quit pgpeekCtrl+C- Force quit
List Navigation:
↑/↓ Arrow keys- Navigate up/down in lists (schemas, tables)Enter- Select item and drill down (e.g., select schema → view its tables)Esc- Exit current mode and return to normal navigation
Query Editor Mode:
4- Enter query editor mode- In editing mode:
Esc- Exit editing mode (keeps your query text)Enter- Execute the current query↑/↓ Arrow keys- Navigate through query historyBackspace- Delete characters- Type normally to write SQL queries
Sample Data & Results:
- Automatic scrolling - Use arrow keys to navigate through large result sets
- Column info - View data types, constraints, and defaults in table details
Quick Tips:
- Press any number key (
1-5) from anywhere to jump directly to that section - Use
Escto get out of any editing mode - All data refreshes automatically, or press
rto force refresh
- URL-based connection strings
- Default connection support
- Connection testing and validation
- Overview - Database size, table count, connection info
- Schema Browser - List all schemas with table counts
- Table Browser - Tables with row counts and sizes
- Column Inspector - Data types, constraints, defaults
- SQL Editor - Full SQL support with syntax awareness
- Query History - Navigate previous queries with arrow keys
- Result Display - Paginated results with column info
- Execution Stats - Query time and row counts
- Saved Queries - Store frequently used queries
- Query History - Automatic history tracking
- Quick Commands - Natural language shortcuts
- Clean TUI - Built with ratatui for smooth navigation
- Status Messages - Clear feedback on all operations
- Error Handling - Helpful error messages and recovery
- Responsive Layout - Adapts to terminal size
pgpeek stores configuration in ~/.config/pgpeek/config.toml:
[settings]
page_size = 100
auto_refresh = false
theme = "default"
show_row_numbers = true
query_history_size = 50
[connections]
[connections.local]
name = "Local Development"
host = "localhost"
port = 5432
database = "myapp_dev"
username = "postgres"
password = "secret"
[connections.prod]
name = "Production"
host = "prod-db.example.com"
port = 5432
database = "myapp"
username = "app_user"
ssl_mode = "require"
[saved_queries]
[saved_queries.active_users]
name = "Active Users"
description = "Users active in last 30 days"
sql = "SELECT COUNT(*) FROM users WHERE last_login > NOW() - INTERVAL '30 days'"
created_at = "2024-01-15T10:30:00Z"
connection = "prod"-- Simple table exploration
SELECT * FROM users LIMIT 10;
-- Filter and search
SELECT * FROM orders WHERE status = 'pending' ORDER BY created_at DESC;
-- Aggregations
SELECT country, COUNT(*) as user_count
FROM users
GROUP BY country
ORDER BY user_count DESC;SHOW TABLES- List all tablesDESCRIBE users- Show table structureEXPLAIN SELECT * FROM orders- Query execution plan
- Ctrl+C - Quick exit from anywhere
- Arrow keys - Navigate query history in editor
- Tab - Future autocomplete support
- Escape - Always gets you back to normal mode
# Basic connection
postgres://username:password@hostname:port/database
# With SSL
postgres://user:pass@host:5432/db?sslmode=require
# Local development
postgres://postgres@localhost/myapp
# Production with SSL
postgres://app_user:secret@prod.db.com:5432/app?sslmode=require- Use
LIMITfor large tables - Enable auto-refresh for monitoring
- Save frequently used queries
- Use the overview to understand database size
Create reusable queries for common operations:
# In the query editor, save useful queries
# They'll be stored in your config and accessible via the saved queries menu# Set up different environments
pgpeek add local postgres://postgres@localhost/myapp_dev
pgpeek add staging postgres://user:pass@staging.db.com/myapp
pgpeek add prod postgres://user:pass@prod.db.com/myapp --default
# Quick switching
pgpeek explore local
pgpeek explore staging
pgpeek explore prod# Test all connections
for conn in $(pgpeek list --names-only); do
echo "Testing $conn..."
pgpeek test "$conn"
done# Test your connection first
pgpeek test mydb
# Check connection details
pgpeek show mydb
# Common issues:
# - Wrong credentials
# - SSL configuration
# - Network connectivity
# - Database permissions- Large result sets: Use
LIMITclauses - Slow queries: Check with
EXPLAIN - Network latency: Consider connection pooling
- Memory usage: Adjust page_size in config
# Reset configuration
rm ~/.config/pgpeek/config.toml
pgpeek init
# Backup your config
cp ~/.config/pgpeek/config.toml ~/pgpeek-backup.toml- Passwords are stored in plain text in config (use environment variables in production)
- SSL connections supported via connection string parameters
- Read-only mode by default (configurable)
- Local config stored in user's config directory
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone and build
git clone https://github.com/simplysabir/pgpeek.git
cd pgpeek
cargo build
# Run tests
cargo test
# Run locally
cargo run -- init
cargo run -- add local postgres://postgres@localhost/test
cargo run -- exploreGet pgpeek up and running locally with Docker in just a few commands:
- Docker and Docker Compose
- Git
- Clone and start the development environment:
git clone https://github.com/simplysabir/pgpeek.git
cd pgpeek
# Start PostgreSQL database with sample data
docker-compose up -d postgres
# Build and run pgpeek
docker-compose build pgpeek
docker-compose run --rm pgpeek- Set up test database connection:
# Initialize pgpeek configuration
docker-compose run --rm pgpeek init
# Add the test database connection
docker-compose run --rm pgpeek add testdb postgres://pgpeek_user:pgpeek_pass@postgres:5432/testdb --default
# Start exploring the test database
docker-compose run --rm pgpeek exploreFor active development with hot reload:
# Start development environment with source code mounted
docker-compose up -d postgres
docker-compose run --rm pgpeek-dev bash
# Inside the container:
cargo build # Build the project
cargo run # Run pgpeek
cargo test # Run tests
cargo watch -x run # Auto-reload on changesThe docker-compose setup includes:
-
postgres: PostgreSQL 15 with sample data- Database:
testdb - User:
pgpeek_user/ Password:pgpeek_pass - Port:
5432 - Sample schemas:
users,sales,inventory
- Database:
-
pgpeek: Production build of pgpeek- Clean runtime environment
- Persistent config storage
-
pgpeek-dev: Development environment- Full Rust toolchain
- Source code mounted for live editing
- Cargo cache for faster builds
The test database includes realistic sample data:
📂 Schemas:
├── users (profiles, sessions)
├── sales (customers, orders, order_items, order_summary view)
├── inventory (categories, products, stock)
└── public (default schema)
📊 Sample Data:
• 5 user profiles with recent login activity
• 4 customers from different countries
• 5 orders with various statuses
• 5 products across different categories
• Stock data across multiple warehouses
# Build images
docker-compose build
# Start just the database
docker-compose up -d postgres
# Run pgpeek commands
docker-compose run --rm pgpeek [command]
docker-compose run --rm pgpeek init
docker-compose run --rm pgpeek list
docker-compose run --rm pgpeek explore testdb
# Development environment
docker-compose run --rm pgpeek-dev bash
# Clean up
docker-compose down
docker-compose down -v # Remove volumes tooIf you prefer running without Docker:
# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Build and run
cargo build --release
./target/release/pgpeek init
./target/release/pgpeek add local postgres://user:pass@localhost:5432/mydb
./target/release/pgpeek exploreMIT - Use it, abuse it, whatever. Just keep peeking! 🔍
Built with ❤️ in Rust
Because database exploration shouldn't be painful.