我想把生产PostgreSQL数据库复制到开发服务器上.最快、最简单的方法是什么?

推荐答案

您不需要创建中间文件.你可以做到的

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 psqlpg_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

Database相关问答推荐

Django Save 方法在try 向表中添加新记录时出错

使用 noSQL 和 MongoDB 在数据库中存储任何类型文件的最佳方法是什么

如何以编程方式将产品添加到 Opencart 数据库

使用python为组中的每个元素添加一个序列号

有没有办法为 2 个具有不同包名称的应用程序提供 1 个 Firebase 数据库?

Boyce-Codd 范式的良好 KISS 描述是什么?

将 `tsv` 文件插入 postgresql 数据库

从 XML 读取数据

为什么数据库索引使用平衡树,而不是哈希表?

连接池策略效果怎样?

生成和读取条形码

我们如何保存在 sqlite3 中创建的数据库

JPA:处理 OptimisticLockException 的模式

不带 WHERE 子句的 UPDATE 查询

哪个更重要?数据库设计或编码?

有没有一种简单的方法来告诉 alembic 迁移到特定版本?

Google 的 Bigtable 与关系数据库

如何使用 JPA 注释创建连接表?

在具有所需 ForeignKey 引用的 Django (1.8) 应用程序之间移动模型

计算邮政编码...和用户之间的距离.