将PostgreSQL数据库复制到另一个服务器 [英] Copying PostgreSQL database to another server
问题描述
我想将一个生产的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 $ c $
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屋!