Create a snapshot of postgres database
When writing migrations I sometimes damage my database, also when working on different sub-projects and you want to have a DB in sync with production and without migrations from project you are not working on currently.
First, list your databases in psql:
psql -U <user> -l
Then do a copy of the one you are interested in:
createdb -O <user> -T <db_to_be_cloned> <clone_name>
Then if something goes wrong you first delete the DB that got damaged:
dropdb <db_to_be_deleted>
And do the createdb
again.
You may also be interested in renaming the db:
psql -U <user>
ALTER DATABASE <old_name> RENAME TO <new_name>
Cheers!
Written by Daniel Kosalla
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Backup
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#