六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 138|回复: 0

How to export data from postgresql and reload

[复制链接]

升级  72%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
36
 楼主| 发表于 2013-1-30 01:26:03 | 显示全部楼层 |阅读模式
Well, Recently I need to work on ubuntu and windows temporately. There are two postgresql servers that are running on ubuntu and windows respectively. But I need the data on both servers is consistent, so I need export the data then reload it after switching workstation. 
 
After doing some research, I found one build-in command in postgresql server does the tricks. pg_dump and pg_dumpall. Here I only use pg_dump to accomplish my task.
 
Export:
 
pg_dump -c scportal -h localhost -U ethanz > /home/ethanz/database_dump1.sql 
 
-c--cleanOutput commands to clean (drop) database objects prior to outputting the commands for creating them. (Restore might generate some harmless errors.)This option is only meaningful for the plain-text format. For the archive formats, you can specify the option when you call pg_restore. That is exactly what I need, connect to my local server, export the sql.
 
Then I can put the exported sql to svn or wherever. After switching the workstation, I'm able to synchrnize the data from the output sql file
 
Load:

ethanz@ethanz-U:~$ psql -d scportal -h localhost -U ethanz -f /home/ethanz/database_dump1.sql Then postgresql will automatically drop the database, index, table, sequence and recreate them then load the data. I think it's a good solution to resynchronize small buntch of data. It's not suitable to huge database.
 
 
This article is only for reference.
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表