您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Postgresql 数据库 的导入导出

2024/3/28 19:30:32发布10次查看
命令操作: 数据的导出: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(用户名)  数据库名(缺省时同用户名)
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
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”。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product