A powerful Terminal User Interface (TUI) application for exploring and managing PostgreSQL databases without writing SQL queries.
- π No SQL Required: Navigate databases using an intuitive UI
- ποΈ Comprehensive Explorer: Browse tables, views, indexes, functions, sequences, materialized views, and custom types
- π Safety First: Built-in query filtering with whitelist/blacklist
- π Multi-Database: Seamlessly switch between multiple databases
- πͺ Resilient: Graceful handling of connection failures
- β¨οΈ Keyboard-Driven: Full keyboard navigation with customizable shortcuts
- π psql Emulation: Supports common psql meta-commands (\dt, \dn, etc.)
- π Data Export: Export query results to CSV, JSON, Excel, and more
- π¨ Themeable: Dark and light themes with customizable colors
- π Clean Logging: Logs written to file, not cluttering your terminal
- Python 3.10 or higher
- PostgreSQL client libraries
# Clone the repository
git clone https://github.com/StakeSquid/pgAdminTUI.git
cd pgAdminTUI
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtYou can configure database connections using any one of the following methods. You don't need to use all of them - pick the one that works best for your setup.
Specify a custom configuration file using the --config option:
# Use a specific config file
python -m src.main --config /path/to/my-config.yaml
# Examples
python -m src.main --config ~/configs/production-dbs.yaml
python -m src.main -c staging.yamlCreate a databases.yaml file in one of these locations:
- Current directory
~/.pgadmintui/databases.yaml
cp databases.yaml.example databases.yaml
# Edit databases.yaml and add your credentials
python -m src.main# databases.yaml
databases:
- name: "mydb"
host: "localhost"
port: 5432
database: "mydb"
username: "myuser"
password: "mypass"
ssl_mode: "prefer"Set a DATABASE_URL environment variable:
export DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"
python -m src.mainUse a configuration file that references environment variables:
# databases.yaml
databases:
- name: "production"
host: "prod.example.com"
port: 5432
database: "mydb"
username: "${DB_USER}" # Will read from environment
password: "${DB_PASS}" # Will read from environmentThen set the environment variables:
export DB_USER=myuser
export DB_PASS=mypass
python -m src.mainThe application loads database configurations in this order:
- Custom config file (if specified with
--config) - databases.yaml file in standard locations (if no
--configprovided) - Environment variables (if no config file found)
- Uses
DATABASE_URLif set
- Uses
To connect to multiple databases, use the databases.yaml file:
databases:
- name: "development"
host: "localhost"
database: "dev_db"
username: "dev_user"
password: "dev_pass"
- name: "production"
host: "prod.example.com"
database: "prod_db"
username: "${PROD_USER}"
password: "${PROD_PASS}"
ssl_mode: "require"# Run with default configuration (looks for databases.yaml)
python -m src.main
# Run with custom config file
python -m src.main --config /path/to/config.yaml
python -m src.main -c production.yaml
# Run with debug logging
python -m src.main --debug
# Combine options
python -m src.main --config staging.yaml --debugCtrl+Q- Quit applicationF1- Show helpF5- Refresh current viewCtrl+Tab- Next databaseCtrl+Shift+Tab- Previous database/- Search:- Command mode
Tab- Switch focus between panelsArrow Keys- Navigate within panelsEnter- Select/Expand itemSpace- Toggle expand/collapse
F2- Enter query modeCtrl+Enter- Execute queryCtrl+C- Copy selected cellF3- Export resultsF4- Filter results
The application supports common psql meta-commands:
\l- List databases\dn- List schemas\dt- List tables\dt+- List tables with sizes\dv- List views\df- List functions\di- List indexes\ds- List sequences\du- List users/roles\d [table]- Describe table\?- Show help
The application includes comprehensive safety features:
- Whitelist: Only allows specified safe commands
- Blacklist: Blocks dangerous commands
- Read-Only Mode: Prevents all write operations
- Transaction Wrapping: Auto-wraps dangerous queries
- Confirmation Dialogs: Requires confirmation for destructive operations
Edit config/commands/whitelist.yaml and config/commands/blacklist.yaml to customize safety rules.
pytest tests/# Type checking
mypy src/
# Formatting
black src/
# Linting
flake8 src/The application is built with a modular architecture:
- Core: Connection management, query execution, and security
- UI: Textual-based TUI widgets and layouts
- Utils: Configuration, psql emulation, and data export
- Models: Data models for database objects
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Textual - An amazing TUI framework
- Inspired by pgAdmin and psql
- PostgreSQL community for excellent documentation