将PostgreSQL数据库复制到另一个服务器 [英] Copying PostgreSQL database to another server

查看:2067
本文介绍了将PostgreSQL数据库复制到另一个服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个生产的PostgreSQL数据库复制到开发服务器。

I'm looking to copy a production PostgreSQL database to a development server. What's the quickest, easiest way to go about doing this?

推荐答案

您不需要创建一个中间文件。你可以做

You don't need to create an intermediate file. You can do

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

使用 psql

using psql or pg_dump to connect to a remote host.

使用大数据库或缓慢的连接,可以转储一个远程主机的 pg_dump 文件和传输文件压缩可能会更快。

With a big database or a slow connection, dumping a file and transfering the file compressed may be faster.

正如Kornel所说,没有必要转储到中间文件,如果你想工作压缩,你可以使用压缩的隧道

As Kornel said there is no need to dump to a intermediate file, if you want to work 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"

但此解决方案还需要结束。

but this solution also requires to get a session in both ends.

这篇关于将PostgreSQL数据库复制到另一个服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆