postgres的导出和备份

来源:互联网 发布:淘宝店铺模板有什么用 编辑:程序博客网 时间:2024/05/29 08:22

备份:
切换到postgres用户,然后执行:

pg_dump netcube > /tmp/netcube_backup_2.sql 

恢复:
切换到postgres用户,然后执行psql:

#create database dbname#create user username with password '**';#alter database netcube owner to username;#alter user username superuser;
  • 第一句是创建数据库
  • 第二句是创建个用户
  • 第三句是把数据库netcube权限归属username用户
  • 赋予用户username超级用户权限。
    退出psql的shell,执行如下导入数据
psql -h localhost -p 5432 -d dbname -U username -f /data/netcube_backup_2.sql

这个-U好像要跟导出时候的数据库的权限绑定一起的。所以要建一个的