简体   繁体   English

如果 pg_restore 正在进行,我们会在应用程序中遇到任何运行时问题吗?

[英]Will we face any runtime issue in application if pg_restore is in progress?

I am new to postgres restore thing.我是 postgres 恢复的新手。 We have an application in which multiple services are using postgres DB.我们有一个应用程序,其中多个服务使用 postgres DB。 We are adding support of Backup/Restore functionality for this application.我们正在为此应用程序添加对备份/恢复功能的支持。

It will take dump using pg_dump.它将使用 pg_dump 进行转储。 And when user triggers restore workflow, it will invoke "pg_restore".当用户触发恢复工作流时,它会调用“pg_restore”。

So if "pg_restore" is running and at that time application is running some queries what will be the impact?因此,如果“pg_restore”正在运行并且当时应用程序正在运行一些查询,将会产生什么影响? Will it face any runtime errors?它会面临任何运行时错误吗? Will existing DB connections be dropped by postgres during pg_restore?在 pg_restore 期间,postgres 会删除现有的数据库连接吗?

No, you have to disconnect the users before you run pg_restore .不,您必须在运行pg_restore之前断开用户连接。

pg_restore expects an empty database, but you can use the options --clean and --create to drop and re-create the database. pg_restore需要一个空数据库,但您可以使用选项--clean--create删除并重新创建数据库。 Now DROP DATABASE will block until the last session has disconnected from the database.现在DROP DATABASE将阻塞,直到最后一个会话与数据库断开连接。

So it is up to you to first disconnect the sessions, either by calling the pg_terminate_backend functoin on the appropriate sessoins or by using DROP DATABASE ... (FORCE) , which exists from v13 on.因此,首先要断开会话,方法是在适当的 sessoins 上调用pg_terminate_backend functoin 或使用DROP DATABASE ... (FORCE) ,它从 v13 开始就存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM