Whether you’re building a web app, experimenting with Flask or Django, or managing small projects locally β PostgreSQL is a rock-solid, open-source database system that fits perfectly. Hereβs your beginner-to-intermediate guide, tailored for local macOS setups.
π§ 1. Checking if PostgreSQL is Running
Check via Homebrew Services
If you installed PostgreSQL via Homebrew (recommended on macOS), run:brew services list
You should see something like: postgresql@14 started user ... β meaning PostgreSQL is running in the background as a LaunchAgent.
Check if the server is accepting connections
Run: pg_isready
If it returns /tmp:5432 - accepting connections, your server is up.
π 2. Understanding Your Databases
List all existing databases:psql -U $(whoami) -l
Youβll typically see databases like:
-
datenbank β your project-specific database
-
postgres β default admin DB
-
template0 β read-only base template
-
template1 β editable template used when creating new DBs
Tip: You only need to use datenbank. The rest are system defaults.
π 3. Do I Need a Password?
By default: No. PostgreSQL on macOS uses „peer authentication“, trusting your local macOS user.
Try: psql -U $(whoami) -d datenbank
If youβre in without a password prompt, youβre fine.
Set a password only if:
-
You want remote access (Docker, cloud, staging)
-
You need separate roles (e.g., app vs. admin)
-
You’re preparing for CI/CD
Set it via SQL:ALTER USER user WITH PASSWORD 'yoursecurepassword';
Update your .env config:DATABASE_URL=postgresql://user:yoursecurepassword@localhost:5432/datenbank
πΎ 4. Backing Up and Restoring Your Database
Why it matters: Backups are your safety net. Make them part of your routine.
Backup your data
Run: pg_dump -U user -d datenbank > datenbank.sql
Optional: Compress it with gzip.
Restore from backup (clean start)
-
Delete existing DB:
dropdb -U user datenbank -
Recreate it:
createdb -U user datenbank -
Restore it:
psql -U user -d datenbank < datenbank.sql
π§ͺ Safer Approach: Test the Restore First
Donβt risk overwriting your live DB. Test like a pro.
-
Create a test DB:
createdb -U user datenbank_restoretest -
Import backup:
psql -U user -d datenbank_restoretest < datenbank.sql -
Change your
.env:DATABASE_URL=postgresql://user@localhost:5432/datenbank_restoretest -
Start your app and verify everything works.
This avoids surprises and confirms your backup is actually usable.
π 5. A Simple Web Interface: pgweb
If you’re used to phpMyAdmin and want something fast and simple for PostgreSQL:
Install: brew install pgweb
Start it: pgweb --db=postgresql://user@localhost:5432/datenbank
Then open http://localhost:8081
Features:
-
Table browsing
-
SQL console
-
Edit/view data
-
Export
All in one lightweight browser app.
π οΈ One-Click Starter Script (Optional)
Create a file called start-pgweb.sh and paste:
Make it executable with chmod +x start-pgweb.sh, then run it: ./start-pgweb.sh
β Final Thoughts
You now have:
-
β A fully working PostgreSQL setup
-
β Safe local access
-
β Reliable backup & restore workflows
-
β A tested approach to avoid data loss
-
β A browser-based interface for everyday tasks
π οΈ Optional Next Steps
Once you’re comfortable:
-
Use
pg_restorefor binary/custom backups -
Manage user roles and permissions
-
Use Docker for isolated dev databases
-
Analyze queries with
EXPLAIN -
Try GUI tools like pgAdmin, TablePlus, or DBeaver
For most local and solo projects, this guide gets you 95% of the way.
Found this helpful?
Share it, bookmark it, or use it as your teamβs PostgreSQL jumpstart.
Need a downloadable version? Let me know β happy to help!