Mastodon Mastodon - pg_dump and pg_restore
 logo
  • Home 
  • Tags 
  • Blog posts 
  1. Home
  2. Blog posts
  3. pg_dump and pg_restore

pg_dump and pg_restore

Posted on April 7, 2023  (Last modified on July 2, 2024) • 1 min read • 124 words
Postgres   Snippet  
Postgres   Snippet  
Share via

Since I can never remember … . Using pg_dump and pg_restore, tested with AWS RDS.

First option, pg_dump can create SQL dumps, which can be read from psql.

# save database; "user" can be admin user (tested) or db_user (untested)
pg_dump    -p my-db.host   -U user      -d db   > my_backup.sql

# restore database; maybe you can also use the admin user here (untested)
psql       -p my-db.host   -U db_user   -d db   < my_backup.sql

Second option, let’s now create a pg_dump “custom” dump file, and restore that with pg_restore.

# save the db ... (add "-v" for more verbosity)
pg_dump    -p my-db.host   -U user      -d db   -Fc -b -f   my_dump_file.pg_dump

# and restore it. (add "-v" for more verbosity)
pg_restore -p my-db.host   -U db_user   -d db   -1          my_dump_file.pg_dump
 Getting started with Dagster
Terraform for_each and output values 
In case you want to follow me

Here are some links. The further to the right, the less active.

           
(c) Axel Bock | Powered by Hinode.
Link copied to clipboard
Code copied to clipboard