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.

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

Image of Datadog

Get the real story behind DevSecOps

Explore data from thousands of apps to uncover how container image size, deployment frequency, and runtime context affect real-world security. Discover seven key insights that can help you build and ship more secure software.

Read the Report

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay