Sep 24, 2017 PostgreSQL 中文版
In the previous post, we’ve learned how to create database and user using PostgreSQL. In addition to that, you might also want to know how to backup and restore your database, right? So, this post is about how to do that.
There are various ways to backup a database. I’m going to introduce the simplest way: dump all data into a single text file. To dump data:
pg_dump [database] > /path/to/[backup-file-name].txt
To restore a database, you have to create an empty database:
psql -c "CREATE DATABASE [database];"
After that, let’s put data back into the new created database:
psql [database] < [bacup-file-name].txt
That’s it. Don’t forget to backup your database regularly.
If you have any suggestions, questions or even find some typos, feel free to contact me. Thank you! :)
zeckli.devforgalaxy@gmail.com © 2015-2019 zeckli, thanks to Jekyll and GitHub.