DEV Community

Cover image for PostgreSQL Backups Simplified with pg_dump
DbVisualizer
DbVisualizer

Posted on

1

PostgreSQL Backups Simplified with pg_dump

pg_dump is an essential tool for creating PostgreSQL backups. This guide highlights key features and examples to streamline your backup process.

SQL Script Backup

pg_dump -U admin -d company -f company_backup.sql
Enter fullscreen mode Exit fullscreen mode

Restore using:

psql -d new_company -f company_backup.sql
Enter fullscreen mode Exit fullscreen mode

Directory-Format Archive

pg_dump -U admin -d company -F d -f company_backup
Enter fullscreen mode Exit fullscreen mode

Produces a directory with .dat.gz files.

Export Data Only

pg_dump -U admin -d company -f company_backup.sql --data-only
Enter fullscreen mode Exit fullscreen mode

Export Specific Schemas

pg_dump -U admin -d company -n 'p*' -f company_backup.sql
Enter fullscreen mode Exit fullscreen mode

FAQ

Where does pg_dump output?
Outputs to stdout; redirect with >.

Path to pg_dump.exe?
Found in C:\Program Files\PostgreSQL\<version>\bin\pg_dump.exe.

Can pg_dump be run remotely?
Yes, using -h, -U, and -d options with remote access enabled.

pg_dump vs. pg_dumpall?
pg_dump backs up single databases; pg_dumpall backs up all databases on the server.

Conclusion

pg_dump simplifies PostgreSQL backups. For more detailed guidance, read the article A Complete Guide to pg_dump With Examples, Tips, and Tricks.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay