将表空间从一个 postgresql 实例复制到另一个实例

发布于 2024-08-18 08:53:04 字数 586 浏览 2 评论 0原文

我正在寻找一种方法来快速将数据库从一台 postgresql 服务器“克隆”到另一台服务器。

假设...

  • 我有一个在 HostA 上运行的 postgresql 服务器,为 2 个数据库提供服务
  • 我在 HostA 上安装了 2 个设备,每个设备存储其中一个数据库的数据(即 1 个数据库 => 1 个表空间 => 1 个设备)
  • 我我能够通过某种谨慎的方法获得“安全”的时间点快照
  • 我能够一致且安全地生成所使用的 2 个设备中任何一个的克隆(我什至可以假设两个数据库仅接收读取)
  • 涉及的主机是 CentOS 5.4

是否可以在 HostB 上托管第二个 postgresql 服务器,挂载克隆设备之一并让相应的数据库“弹出”存在? (有点像在 MySQL 中复制 MyISAM 表文件)。

如果这完全可能,那么机制是什么(即我应该查看哪些 DDL 或 pg 命令)?

对我来说,能够独立地移动各个数据库非常重要。但如果这是不可能的,类似的方法是否可以在服务器级别工作(尝试通过将 datadir 复制到具有相同 postgresql 安装的主机来克隆和重新生成服务器)?

I'm looking for a way to quickly "clone" a database from 1 postgresql server to another.

Assuming...

  • I have a postgresql server running on HostA, serving 2 databases
  • I have 2 devices mounted on HostA, each device stores the data for one of the database (i.e. 1 database => 1 tablespace => 1 device )
  • I am able to obtain a "safe" point in time snapshot through some careful method
  • I am able to consistently and safely produce a clone of any of the 2 devices used (I could even assume both database only ever receive reads)
  • The hosts involved are CentOS 5.4

Is it possible to host a second postgresql server on HostB, mount one of the cloned devices and get the corresponding database to "pop" into existence? (Kind of like when you copy the MyISAM table files in MySQL).

If this is at all possible, what is the mechanism (i.e. what DDL should I look into or pg commands)?

It's important for me to be able to move individual databases in isolation of each other. But if this isn't possible, would a similar approach work at a server level (trying to clone and respawn a server by copying the datadir over to a host with the same postgresql install) ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

堇年纸鸢 2024-08-25 08:53:04

这并不容易,因为数据库之间共享许多文件,这意味着同一安装中的每个数据库都依赖于此。

您可以在服务器级别或集群级别执行此操作,但不能在单个数据库级别执行此操作。只需确保复制/克隆整个数据目录和所有外部表空间。只要您可以原子地进行克隆(无论是在同一文件系统上还是使用可以跨文件系统进行原子克隆的系统),您甚至不需要停止 hostA 上的数据库来执行此操作。

Not easily, because there are a number of files that are shared between databases which means each database in the same install is dependent on this.

You can do it at the server level, or at the cluster level, but not at individual database level. Just be sure to copy/clone over the whole data directory and all external tablespaces. As long as you can make the clone atomically (either on the same filesystem or with a system that can do atomic clones across filesystems), you don't even need to stop the database on hostA to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文