码迷,mamicode.com
首页 > 其他好文 > 详细

利用管道迁移数据

时间:2014-11-06 11:09:31      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:blog   io   for   数据   on   2014   问题   log   ad   


磁盘空间不足的情况下,利用命名或者匿名管道迁移和导入数据;需要注意命名管道的权限问题。

0. Name PIP 0
[pg@h1 ~]$ psql gtlions -ac "select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;"
select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;
 tab | count
-----+-------
 t3  |   100
 t4  |     0
(2 rows)
 
[pg@h1 ~]$ mknod syncpip p
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/sync'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/sync'"  
ERROR:  could not open file "/home/pg/sync" for reading: No such file or directory
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"        
COPY 100
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -ac "select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;"
select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;
 tab | count
-----+-------
 t3  |   100
 t4  |   400
(2 rows)
1. Name PIP 1
[pg@h1 ~]$ rm -rf sync*
[pg@h1 ~]$ mkfifo syncpip
[pg@h1 ~]$ ll syncpip
prw-rw-r-- 1 pg pg 0 11月  6 09:15 syncpip
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -ac "select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;"
select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;
 tab | count
-----+-------
 t3  |   100
 t4  |   800
(2 rows)
 
2. UnName PIP
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to stdout"|psql gtlions -p 5432 -c "copy t4 from stdin"                                      
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to stdout"|psql gtlions -p 5432 -c "copy t4 from stdin"  
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to stdout"|psql gtlions -p 5432 -c "copy t4 from stdin"  
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to stdout"|psql gtlions -p 5432 -c "copy t4 from stdin"  
[pg@h1 ~]$ psql gtlions -p 5432 -c "copy t3 to '/home/pg/syncpip'"|psql gtlions -p 5432 -c "copy t4 from '/home/pg/syncpip'"  
COPY 100
[pg@h1 ~]$ psql gtlions -ac "select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;"                        
select 't3' tab,count(*) from t3 union all select 't4',count(*) from t4;
 tab | count
-----+-------
 t3  |   100
 t4  |  1300
(2 rows)


-EOF-

利用管道迁移数据

标签:blog   io   for   数据   on   2014   问题   log   ad   

原文地址:http://blog.csdn.net/gtlions/article/details/40855701

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!