Home >Database >Mysql Tutorial >PostgreSQL 数据库导入导出操作

PostgreSQL 数据库导入导出操作

PHP中文网
PHP中文网Original
2016-06-07 17:14:201744browse

PostgreSQL 数据库操作简要说明 PostgreSQL数据库版本 psql --versionpsql (PostgreSQL) 9.1.3 一、数据库备份 1、备份数据库结构





Linux公社


首页 → 数据库技术




背景:

阅读新闻




PostgreSQL 数据库导入导出操作

[日期:2012-06-08] 来源:Linux社区  作者:hehehe [字体:]


PostgreSQL 数据库操作简要说明

PostgreSQL数据库版本

psql --version
psql (PostgreSQL) 9.1.3

一、数据库备份

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”。

linux

  • 0


浅谈Oracle执行计划

如何理解Oracle中“通过角色授权”需要用户重新登陆


相关资讯       PostgreSQL教程 


图片资讯      



  • PostgreSQL集群方案hot standby 安装和测试

    PostgreSQL集群方案


本文评论  查看全部评论 (0)



评论声明


最新资讯


本周热门

Linux公社简介 - 广告服务 - 网站地图 - 帮助信息 - 联系我们
本站(LinuxIDC)所刊载文章不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。


Copyright © 2006-2011 Linux公社 All rights reserved 浙ICP备06018118号

以上就是PostgreSQL 数据库导入导出操作的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn