All-in-one powerful and human-friendly PostgreSQL CLI Manager
Explore, modify, and monitor PostgreSQL databases from the terminal — no GUI required.
PgShell is a terminal-based tool that gives you full control over PostgreSQL through an interactive menu and direct query mode. Connect to local or cloud databases, browse tables, run SQL, monitor activity — all from your favorite terminal.
| 🖥️ | Interactive UI — Guided menus for common tasks |
| ⚡ | Direct queries — pgshell query "SELECT * FROM users" |
| 🔐 | Flexible config — .env, URI, or interactive setup |
| 📊 | Formatted output — Clean tables with syntax highlighting |
- Requirements
- Installation
- Configuration
- Usage
- Interactive UI
- Direct Query Mode
- Examples
- Project Structure
- License
- Node.js 18+
- PostgreSQL server (local or remote)
- Database credentials
Quick install — Use PgShell from anywhere with a single command:
npm install -g pgshellThen run:
pgshell
# or
pgshell query "SELECT * FROM users LIMIT 5"From source (for development or contribution):
git clone https://github.com/Foisalislambd/pgshell
cd pgshell
npm install
npm run buildRun the interactive UI:
node dist/index.js
# or
npx tsx src/index.tsDevelopment (with hot reload):
npm run devLocal link (run from source without publishing):
npm link
pgshellPgShell reads credentials from a .env file in the current directory where you run pgshell. Create it in your project folder before running.
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=your_password
DB_NAME=your_databaseDATABASE_URL="postgresql://user:password@localhost:5432/dbname"
DATABASE_URLoverrides individual variables if both exist.
PGUSER=postgres
PGPASSWORD=yourpassword
PGHOST=localhost
PGPORT=5432
PGDATABASE=yourdatabaseSSL is enabled automatically for sslmode=require, amazonaws.com, or supabase.com in the connection string.
- Install:
npm install -g pgshell - Create a
.envfile in your project directory (see Configuration) - Run
pgshell— PgShell connects automatically; otherwise it prompts for connection details
Run pgshell or pgshell ui to open the interactive menu. Works with or without .env.
| Menu Option | Description |
|---|---|
| 📋 List all tables | Tables in public schema with owner and row estimates |
| 🔍 View table data | Browse rows with configurable limit |
| 📖 Table structure | Columns, types, nullability, defaults |
| ➕ Create new table | Define tables with column syntax |
| 📥 Add new row | Insert with guided prompts per column |
| 🗑️ Delete one table | Drop a single table (with confirmation) |
| 🚨 Delete all tables | Drop all public tables (extra confirmation) |
| ⚡ Run custom SQL | Execute any SQL command |
| 📊 Monitor active queries | Live view of running queries |
| ❌ Disconnect & Exit | Close connection and quit |
- Localhost — Enter host, port, user, password, database
- External / URI — Paste full
postgresql://connection string
- Ctrl+C — Safe exit
- Blank insert fields → use DEFAULT or NULL
- Table names: letters, numbers, underscores only
- Dangerous SQL is blocked in table creation
Run a single query without the UI. Requires .env credentials.
pgshell query "SELECT * FROM users LIMIT 5"# Select
pgshell query "SELECT * FROM products WHERE price > 100"
# Count
pgshell query "SELECT COUNT(*) FROM orders"
# Insert
pgshell query "INSERT INTO logs (message) VALUES ('test')"Results appear as formatted tables. Exits with code 1 on errors.
List tables
pgshell
# → List all tablesCreate table
pgshell
# → Create new table
# Name: users
# Columns: id SERIAL PRIMARY KEY, email VARCHAR(255), created_at TIMESTAMP DEFAULT NOW()Insert row
pgshell
# → Add new row → select table → enter valuesQuick query
pgshell query "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"pgshell/
├── src/
│ ├── index.ts # CLI entry, Commander
│ ├── commands/query.ts # Direct query command
│ ├── db/
│ │ ├── client.ts # Connection pool
│ │ └── env.ts # .env credentials
│ ├── ui/
│ │ ├── mainMenu.ts # Interactive menu
│ │ └── tableRenderer.ts # Result formatting
│ └── utils/
│ ├── banner.ts # ASCII banner
│ └── sanitizeError.ts # Error sanitization
├── .env.example
├── package.json
└── README.md
| Script | Description |
|---|---|
npm run dev |
Run with hot reload |
npm run build |
Build to dist/ |
npm start |
Run built output |
ISC