A lightweight admin interface and CLI toolkit for PostgreSQL, built with Flask, SQLAlchemy, and psycopg2.
Manage your databases and tables with ease – via web or terminal.
To get started, clone this repository to your local machine using Git:
git clone https://github.com/TamerOnLine/postgres-admin-tools.git
cd postgres-admin-tools
- Make sure you have Git installed.
- You can download it from.
- 🔐 Secure user system with Flask-Login (default admin:
admin/12345
) - ⚙️ Create or drop PostgreSQL databases
- 🧱 Manage tables (create / migrate / drop) via SQLAlchemy
- 💾 Full database backup & restore using
pg_dump
/psql
- 🧩 Easy environment config via
.env
file - 🌐 Flask-based web UI ready out of the box
📽️ Quick demo of the PostgreSQL Admin Tools in action
Technology | Description |
---|---|
Python | Core programming language |
PostgreSQL | Relational database engine |
SQLAlchemy | ORM for database modeling |
psycopg2 | PostgreSQL driver for Python |
python-dotenv | Load .env variables into runtime |
postgres-admin-tools/
├── myapp.py # Flask app with login & DB panel
├── requirements.txt
├── LICENSE
├── README.md
└── models/
├── models_definitions.py # SQLAlchemy models
└── db_postgres/
├── create.py # Create DB if not exists
├── drop.py # Drop DB (safe disconnect)
├── drop_table.py # Drop individual/all tables
├── manage_tables.py # Schema updates
├── BACKUP.py # Backup to SQL file
├── RESTORE.py # Restore from backup
└── db_config.py # Load from .env
Create a .env
file in the root directory:
DATABASE_URL=postgresql://user:password@localhost:5432/your_db
SECRET_KEY=your_secret_here
# Windows
py -3.12 -m venv venv
.\venv\Scripts\Activate
# macOS / Linux
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
py .\models\db_postgres\create.py
py .\models\db_postgres\drop.py
py .\models\db_postgres\drop_table.py
py .\models\db_postgres\manage_tables.py
py .\models\db_postgres\BACKUP.py
py .\models\db_postgres\RESTORE.py
The system automatically creates a default admin user on first run if no user with username admin
is found.
- Username:
admin
- Password:
12345
To manually trigger this, run the following command:
py .\models\models_definitions.py
You can modify this logic in models/models_definitions.py
.
If DATABASE_URL
is not set in the .env
, the system defaults to SQLite (sqlite:///test.db
) for quick testing.
Note: Scripts like
create.py
,BACKUP.py
, etc., require PostgreSQL and do not support SQLite.
Operation | Script | Mode |
---|---|---|
🏗️ Create Database | create.py |
CLI |
❌ Drop Database | drop.py |
CLI |
🧹 Drop Tables | drop_table.py |
Interactive CLI |
🧩 Manage Tables | manage_tables.py |
Interactive CLI |
💾 Backup Database | BACKUP.py |
CLI |
♻️ Restore from Backup | RESTORE.py |
Interactive CLI |
This project is licensed under the MIT License.
See the LICENSE file for details.
Tamer Hamad Faour
GitHub: @TamerOnLine