A powerful, universal CLI and interactive terminal tool for effortless PostgreSQL administration across any Linux distribution and macOS.
Whether you need to initialize a fresh database cluster, start/stop services, generate copy-paste ready connection strings for your application stack, connect via pgAdmin 4, or run automated backups and restores β mypostgress handles it all with zero fuss.
- π Universal Multi-Distro Support: Works out-of-the-box on Arch Linux / CachyOS / Manjaro, Ubuntu / Debian / Mint, Fedora / RHEL / CentOS / Rocky, openSUSE, Alpine Linux, and macOS.
- π¦ Automatic Dependency & Distro Installer: Detects missing PostgreSQL packages and offers 1-click installation via
pacman,apt,dnf,zypper,apk, orbrew. - π οΈ Smart Cluster Initialization (
initdb): Automatically detects missing/uninitialized/var/lib/postgres/dataclusters and initializes them with proper UTF-8 locales. - π€ 1-Click User & Superuser Setup: Easily creates a matching PostgreSQL superuser role for your Linux user so you can run
psqland development tools without sudo prompts or peer-auth errors. - π Application Connection String Generator: Instantly outputs formatted connection strings for Standard URIs, psql CLI,
.envfiles, Node.js (Prisma / TypeORM / Drizzle / Sequelize), Python (SQLAlchemy / psycopg2 / asyncpg / Django), Go (pgx / lib/pq), Java/Kotlin (JDBC), and PHP (PDO). - π pgAdmin 4 Integration: Automatically finds and launches pgAdmin 4 (Flatpak, Native, Snap, Docker, or Web) and prints server connection parameters. If not installed, it offers an automatic installer.
- πΎ Smart Backup & Restore: Supports both plain SQL (
.sql) and custom compressed archives (.dump,.tar,.backup). Auto-creates target databases during restore if they don't exist. - β‘ Dual Interface: Full-featured interactive menu when run without arguments, plus fast direct CLI commands for scripting and terminal efficiency.
- π Service & Boot Management: Easily start, stop, restart, inspect status with real-time logs, and toggle boot autostart (
enable/disable).
mypostgress installs to ~/.local/bin/mypostgress, which is included in your user $PATH.
# Clone or navigate to the repository
cd ~/App
# Run self-installer
./mypostgress installOnce installed, you can run mypostgress (or the shortcut mypostgres) from any terminal or directory.
Simply type mypostgress without any arguments:
mypostgressββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
mypostgress Universal Management Tool
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Start PostgreSQL
2. Stop PostgreSQL
3. Restart PostgreSQL
4. Check Service Status
5. Show Connection Strings (URI, psql, Node, Python, JDBC...)
6. Open / Connect in pgAdmin 4
7. List All Databases
8. Backup a Database
9. Restore a Database
10. Initialize Database Cluster (initdb)
11. Setup Superuser Role for 'chanduu'
12. Install / Reinstall PostgreSQL (Multi-Distro)
13. Install / Setup pgAdmin 4
14. Enable PostgreSQL on Boot
15. Disable PostgreSQL on Boot
16. Install / Update Global Command
0. Exit
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Select an option [0-16]:
You can run any operation directly from your terminal:
# Service Control
mypostgress start # Start PostgreSQL (auto-detects uninitialized clusters)
mypostgress stop # Stop PostgreSQL service
mypostgress restart # Restart PostgreSQL service
mypostgress status # Check service status & connectivity
# Connection Strings & Tools
mypostgress conn # Interactively generate connection strings
mypostgress conn mydb myuser mypass # Generate connection strings with parameters
mypostgress pgadmin # Launch pgAdmin 4 (with server credentials helper)
# Database Management
mypostgress list # List all databases with size, owner, and encoding
mypostgress backup mydb ~/backups/db.sql # Backup database to plain SQL or .dump
mypostgress restore mydb ~/backups/db.sql # Restore database (prompts to create DB if missing)
# Setup & Maintenance
mypostgress init # Initialize PostgreSQL cluster (initdb)
mypostgress setup-user # Create matching superuser role for current Linux user
mypostgress install-postgres # Install/reinstall PostgreSQL packages via distro package manager
mypostgress install-pgadmin # Install pgAdmin 4 (Flatpak / Native / Docker / Pip)
mypostgress enable # Enable PostgreSQL to start automatically on system boot
mypostgress disable # Disable autostart on boot
# Help & Utility
mypostgress version # Show version and detected OS
mypostgress help # Display help messageGenerates ready-to-paste configurations tailored for your stack:
mypostgress conn my_app_db dev_user my_secret_passOutput:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PostgreSQL Connection Strings Reference β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β’ Database: my_app_db β’ User: dev_user β’ Host: localhost:5432
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Standard Connection URI / URL:
postgresql://dev_user:my_secret_pass@localhost:5432/my_app_db
2. psql CLI Command:
psql -h localhost -p 5432 -U dev_user -d my_app_db
psql "postgresql://dev_user:my_secret_pass@localhost:5432/my_app_db"
3. Environment Variable (.env / Docker):
DATABASE_URL="postgresql://dev_user:my_secret_pass@localhost:5432/my_app_db?schema=public"
4. Node.js (Prisma / TypeORM / Sequelize / pg / Drizzle):
DATABASE_URL="postgresql://dev_user:my_secret_pass@localhost:5432/my_app_db"
5. Python (SQLAlchemy / psycopg2 / asyncpg / Django):
β’ SQLAlchemy: postgresql+psycopg2://dev_user:my_secret_pass@localhost:5432/my_app_db
β’ asyncpg: postgresql+asyncpg://dev_user:my_secret_pass@localhost:5432/my_app_db
6. Go (pgx / lib/pq / GORM / Bun):
postgres://dev_user:my_secret_pass@localhost:5432/my_app_db?sslmode=disable
7. Java / Kotlin (JDBC / Spring Boot):
jdbc:postgresql://localhost:5432/my_app_db?user=dev_user&password=my_secret_pass&sslmode=prefer
8. PHP (PDO / Laravel):
pgsql:host=localhost;port=5432;dbname=my_app_db;user=dev_user
- Smart Detection: Detects Flatpak (
org.pgadmin.pgadmin4), native package (/usr/bin/pgadmin4), Snap, macOS apps, or Docker containers (dpage/pgadmin4). - Connection Parameter Summary: Displays the exact hostname, port, database, and user to input when adding a new server in pgAdmin.
- Auto-Installer: If pgAdmin is not present on your system, it offers multiple installation methods (Flatpak, Native repository, Docker, or Python virtualenv).
Automatically detects format based on filename extension:
-
.sql$\rightarrow$ Plain SQL script -
.dump,.tar,.backup,.fc$\rightarrow$ Custom compressed archive format (pg_dump -F c)
# Plain SQL backup
mypostgress backup ecommerce_db ~/backups/ecommerce.sql
# Compressed custom dump
mypostgress backup ecommerce_db ~/backups/ecommerce.dumpDetects format automatically and uses psql or pg_restore accordingly. If the destination database does not exist, mypostgress will prompt to create it automatically:
mypostgress restore ecommerce_db ~/backups/ecommerce.dump| OS / Distribution | Package Manager | Service Manager | Default Data Directory |
|---|---|---|---|
| Arch Linux / CachyOS / Manjaro | pacman |
systemd |
/var/lib/postgres/data |
| Ubuntu / Debian / Linux Mint / Pop!_OS | apt |
systemd / service |
/var/lib/postgresql/<ver>/main |
| Fedora / RHEL / CentOS / Rocky | dnf / yum |
systemd |
/var/lib/pgsql/data |
| openSUSE / SLES | zypper |
systemd |
/var/lib/pgsql/data |
| Alpine Linux | apk |
OpenRC (rc-service) |
/var/lib/postgresql/data |
| macOS | brew |
brew services / pg_ctl |
/opt/homebrew/var/postgresql@16 |
Override connection settings for remote servers or custom ports:
export PGUSER="postgres" # Default PostgreSQL username (default: postgres / $USER)
export PGHOST="localhost" # PostgreSQL host (default: local socket / localhost)
export PGPORT="5432" # PostgreSQL port (default: 5432)
export PGPASSWORD="your_pass" # PostgreSQL password
export PGDATA="/custom/path" # Custom database cluster directoryA: On Arch/CachyOS/Fedora, database clusters must be initialized before first start. Simply run:
mypostgress startmypostgress will detect the uninitialized cluster, prompt you to initialize it with initdb, and start the service automatically.
A: Run mypostgress setup-user. This creates a superuser role and default database matching your Linux username, enabling passwordless, sudo-free local connections.
A: Run:
mypostgress enableThis project is licensed under the MIT License β feel free to use and customize it for your workflow!