postgresql 数据备份与恢复

http://blog.csdn.net/niuxinzan/article/details/17243103

postgresql数据库、表备份语句
标签: 数据库
2013-12-10 13:46 1206人阅读 评论(0) 收藏 举报
分类:
数据库(8)

PostgreSQL 数据库操作简要说明

PostgreSQL数据库版本

psql –version
psql (PostgreSQL) 9.1.3

下面是在Linux下的操作,在windows下面将su -postgres 换为

运行输入cmd→d:→

cd D:\Program Files\PostgreSQL\9.2\bin,下面创建表、删除表时,需要在postgres下操作,因此需要在创建删除数据库前面输入psql -u postgres

一、数据库备份

1、备份数据库结构

su - postgres
pg_dump -Fc -s -f testdbschema.sql testdb

2、备份数据库数据

su - postgres
pg_dump -Fc -a -f testdbdata.sql testdb

3、备份数据库结构和数据

su - postgres
pg_dump -Fc -f testdbschemadata.sql testdb

4、备份数据库中指定表结构

pg_dump -Fc -s -t citycode -f citycode_schema.sql testdb

5、备份数据库中指定表数据

pg_dump -Fc -a -t citycode -f citycode_data.sql testdb

.6、备份数据库中指定表(结构和数据)

pg_dump -Fc -t citycode -f citycode_schemadata.sql testdb

二、删除数据库

su - postgres

dropdb testdb

三、恢复数据库

1、创建新数据库testdb

su - postgres

createdb testdb;

2、 恢复数据结构(only schema)

su - postgres

pg_restore -s -d testdb testdbschema.sql

3、恢复数据库数据(only data)

su - postgres

pg_restore -a -d testdb testdbdata.sql

4、恢复数据库结构和数据(schema and data)

su - postgres

pg_restore -d testdb testdbschemadata.sql

5、指定表数据恢复

1)删除表

psql testdb

DROP TABLE citycode;

2)恢复表结构

pg_restore -s -t citycode -d testdb citycode_schema.sql

3)恢复表数据

pg_restore -a -t citycode -d testdb citycode_data.sql

4)恢复表(结构和数据)

pg_restore -t citycode -d testdb citycode_schemadata.sql

以上备份恢复相关操作可用于静态(无数据增长)数据库。

重要提示:pg_restore 可用来恢复pg_dump命令以 (Fc\Ft)格式备份的数据文件。执行pg_dump备份命令时若无此格式参数声明,pg_restore 恢复时可能出现错误提示“pg_restore: [archiver] input file does not appear to be a valid archive”。

C:\Users\cennavi-101>D:/software/postgresql/bin/pg_restore.exe -hlocalhost -p5433 -Upostgres -dMap13SprMIFK13 -v “E:\Map13SprMIFK13(Postgresql).backup”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值