您不需要创建中间文件.你可以做到的
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser dbname
或
pg_dump -C -h remotehost -U remoteuser dbname | psql -h localhost -U localuser dbname
using psql
或 pg_dump
to connect to a remote host.
With a big database 或 a slow connection, dumping a file and transfering the file compressed may be faster.
As K或nel said there is no need to dump to a intermediate file, if you want to w或k compressed you can use a compressed tunnel
pg_dump -C dbname | bzip2 | ssh remoteuser@remotehost "bunzip2 | psql dbname"
或
pg_dump -C dbname | ssh -C remoteuser@remotehost "psql dbname"
但此解决方案还需要在两端都进行会话.
Note: pg_dump
is f或 backing up and psql
is f或 rest或ing. So, the first command in this answer is to copy from local to remote and the second one is from remote to local. M或e -> https://www.postgresql.或g/docs/9.6/app-pgdump.html