暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 13 preview - drop database force 自动kill DATABASE 连接

digoal 2019-12-04
629

作者

digoal

日期

2019-12-04

标签

PostgreSQL , drop database force


背景

删除数据库时,需要确保这个数据库上没有其他session,如果有,drop database将失败。

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=80e05a088e4edd421c9c0374d54d787c8a4c0d86

https://www.postgresql.org/docs/devel/sql-dropdatabase.html

```
DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]

where option can be:

FORCE
复制

FORCE
Attempt to terminate all existing connections to the target database. It doesn't terminate if prepared transactions, active logical replication slots or subscriptions are present in the target database.

This will fail if the current user has no permissions to terminate other connections. Required permissions are the same as with pg_terminate_backend, described in Section 9.27.2. This will also fail if we are not able to terminate connections.
```

PG 13新增force接口,自动terminate 被删除数据库上的当前连接。但是注意:

1、当这个数据库有未结束的2pc事务,激活的logical replication slot,或者逻辑订阅时,不会kill session.

2、当没有terminate 权限时,报错。

force一定程度上简化了drop database因为有连接(例如心跳,客户端连接未断开等)造成的drop database失败的问题。

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论