Last active
April 29, 2022 10:16
-
-
Save devhero/b4dc765b7760d582369e to your computer and use it in GitHub Desktop.
postgres backup/restore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo su postgres | |
# BACKUP | |
vacuumdb -U postgres --full --analyze --dbname $DBNAME && pg_dump $DBNAME -Ft -v -U postgres -f /tmp/$DBNAME.tar | |
# RENAME TARGET DB | |
psql | |
alter database $T_DBNAME rename to NEWNAME | |
# OR DROP TARGET DB | |
dropdb $T_DBNAME | |
# RESTORE ON TARGET DB | |
createdb --encoding UNICODE $T_DBNAME && pg_restore /tmp/$DBNAME.tar | psql --dbname $T_DBNAME && vacuumdb --full --analyze --dbname $T_DBNAME | |
# RESTORE FROM SQL | |
psql dbname -f dump.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment