备份数据库:
pg_dump -h localhost -U root demo02 > /home/arno/dumps/demo02.bak
恢复数据库:
psql -h localhost -U root -d demo < demo.bak
备份表:
pg_dump -h localhost -U root demo02 -t books > /home/arno/dumps/books.bak
恢复表:
psql -h localhost -U root -d demo -t books < /home/arno/dumps/books.bak
psql copy to/from用法:
1. 需要使用postgres超级用户登陆数据库
psql -U postgres -d demo02
2. 保存/读取的文件夹需要赋予postgres用户可读写的权限
3. 导出表中数据到文件
copy books to '/opt/Postgresql/9.5/data/xxx.csv' with CSV;
4. 导入文件内容到数据库(增加不是覆盖,以前表中数据保留)
copy books(id,title) from '/opt/Postgresql/9.5/data/xxx.csv' delimiter as ',' csv quote as '"';