postgresql 数据备份与恢复
2017-03-29 17:25
302 查看
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”
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”
相关文章推荐
- PostgreSQL pg_dump&psql 数据的备份与恢复
- PostgreSQL pg_dump&psql 数据的备份与恢复
- Python3.6实现PostgreSql数据表备份与恢复
- postgresql数据备份恢复
- postgresql备份恢复之pg_dump大数据处理
- postgresql 数据备份与恢复
- PostgreSQL pg_dump&psql 数据的备份与恢复
- PostgreSQL备份和恢复数据表
- 注册表故障恢复 必须使用记录或另一备份以恢复包含系统注册表数据的文件。恢复成功
- 备份与恢复windows 2003的AD数据库
- 网络数据的备份和恢复
- ArcSDE 中空间数据的备份与恢复
- 利用VB进行SQL2000的数据备份和恢复
- Oracle+sde数据备份、恢复
- Oracle+sde数据备份、恢复
- Vista数据备份恢复
- 用VB进行SQL2000的数据备份和恢复
- 数据备份还原我有妙招----第3集:自动系统恢复(ASR)备份系统
- ArcSDE中空间数据的备份与恢复
- oracle学习笔记(1)-数据备份与恢复