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_restore
for 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!