如何轻松地将生产 postgresql 数据库克隆到登台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26169715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:38:17  来源:igfitidea点击:

How to easily clone a production postgresql database to staging

ruby-on-railsdatabasepostgresqlruby-on-rails-4psql

提问by raphael_turtle

I have data in a production database but want to test out some new features so I've set up a staging environment on the same server and want to use the data from the production database with my staging app.

我在生产数据库中有数据,但想测试一些新功能,所以我在同一台服务器上设置了一个登台环境,并希望将生产数据库中的数据与我的登台应用程序一起使用。

How can I replicate the data from my rails_production database to my rails_staging database, they both have the same owner (postgres) and share the same password.

如何将数据从 rails_production 数据库复制到 rails_staging 数据库,它们都具有相同的所有者 (postgres) 并共享相同的密码。

回答by Zeki

The easiest way is to use a backup using pg_dump and then restore it to the new database by piping that output into psql. If you can connect to both boxes you can also pipe directly from pg_dump into psql without using the local filesystem.

最简单的方法是使用 pg_dump 使用备份,然后通过将输出管道传输到 psql 将其恢复到新数据库。如果您可以连接到两个盒子,您还可以直接从 pg_dump 管道传输到 psql 而无需使用本地文件系统。

This method is described here:

此处描述了此方法:

Copying PostgreSQL database to another server

将 PostgreSQL 数据库复制到另一台服务器