区别是:
- copy必须使用能够超级用户使用;
- copy .. to file,copy file to ..中的文件都是数据库服务器所在的服务器上的文件。
- \copy 一般用户即可执行
- \copy 保存或者读取的文件是在客户端所在的服务器
比如当使用192.168.17.53连上192.168.17.52的数据库,使用copy tb1 to ‘/home/postgres/aa.txt’,该文件是存放在192.168.17.52上;
当使用\copys时候就会把文件存放到客户端所在的服务器上,即使用\copy tb1 to ‘/home/postgres/aa.sql’,该文件是存放在192.168.17.53上;
环境:
host: 192.168.17.52
client:192.168.17.53
使用192.168.17.53登录到 192.168.17.52做演示:
- 1. 先到192.168.17.52的/home/postgres下看看当前的文件
[root@localhost postgres]# pwd
/home/postgres
[root@localhost postgres]# ls
archive base dump pg_log pp.sql python script soft tb10.csv test.sql
[root@localhost postgres]#
- 2. 使用copy命令进行导出
[postgres@localhost root]$ psql -h 192.168.17.52 -U postgres postgres
Could not change directory to "/root": Permission denied
psql (9.3.5)
Type "help" for help.
postgres=#
postgres=# copy bbs to '/home/postgres/bbs.sql';
copY 31
使用copy的时候文件是保存在服务器端的,切换到192.168.17.52的/home/postgres下看看文件是否存在:
[root@localhost postgres]# pwd
/home/postgres
[root@localhost postgres]# ls
archive base bbs.sql dump pg_log pp.sql python script soft tb10.csv test.sql
- 3. 使用\copy命令进行复制:
在192.168.17.53下:
[postgres@localhost ~]$ pwd
/home/postgres
[postgres@localhost ~]$ ls
archive archive_failover base pg_log script trigger
postgres=# \copy bbs to '/home/postgres/bbs.sql';
postgres=#
在192.168.17.53下在看一下:
[postgres@localhost ~]$ pwd
/home/postgres
[postgres@localhost ~]$ ls
archive archive_failover base bbs.sql pg_log script trigger
使用\copy是备份到客户端上。
恢复的时候也是一样,使用copy是从服务端寻找文件,使用\copy是从客户端上寻找文件。
参考: http://francs3.blog.163.com/blog/static/40576727201412135333388/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。