加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Postgresql 数据库 的导入导出

发布时间:2020-12-13 17:35:35 所属栏目:百科 来源:网络整理
导读:命令操作: 数据的导出:pg_dump -U postgres(用户名) (-t 表名) 数据库名(缺省时同用户名) c:fulldb.sql 数据的导入:psql -U postgres(用户名) 数据库名(缺省时同用户名) C:fulldb.sql pgAdmin操作: 数据的导出:在库名上右击--backup--ok,即将数据保
命令操作:
数据的导出:pg_dump -U postgres(用户名) (-t 表名) 数据库名(缺省时同用户名) > c:fulldb.sql
数据的导入:psql -U postgres(用户名) 数据库名(缺省时同用户名) < C:fulldb.sql

pgAdmin操作:
数据的导出:在库名上右击-->backup-->ok,即将数据保存到.backup文件中。

数据的导入:在库名上右击-->restore-->注意填写.backup文件的路径不能有空格-->ok


------------------------------------------------------------------------------------------------------------------------

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

createdb testdb;


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

pg_restore -s -d testdb testdbschema.sql

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

pg_restore -a -d testdb testdbdata.sql

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

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命令以 (FcFt)格式备份的数据文件。执行pg_dump备份命令时若无此格式参数声明,pg_restore 恢复时可能出现错误提示“pg_restore: [archiver] input file does not appear to be a valid archive”。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读