PG13提供的force选项有什么作用

这篇文章主要讲解了“PG 13提供的force选项有什么作用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PG 13提供的force选项有什么作用”吧!

网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了翁牛特免费建站欢迎大家使用!

在PG 12或以下版本,删除数据库时如存在连接则无法删除,PG 13提供了force选项,可终止相关连接直接删除数据库。

PG 12
创建数据库并连接

[pg12@localhost ~]$ createdb dropdb
[pg12@localhost ~]$ 
[pg12@localhost ~]$ psql -d dropdb
Expanded display is used automatically.
psql (12.1)
Type "help" for help.
[local:/run/pg12]:5120 pg12@dropdb=#

删除数据库,一直在等待,超时后提示

[pg12@localhost ~]$ psql
Expanded display is used automatically.
psql (12.1)
Type "help" for help.
[local:/run/pg12]:5120 pg12@testdb=# drop database dropdb;
ERROR:  database "dropdb" is being accessed by other users
DETAIL:  There is 1 other session using the database.

PG 13
创建数据库并连接

[pg13@localhost ~]$ createdb dropdb
[pg13@localhost ~]$ psql -d dropdb
Expanded display is used automatically.
psql (13devel)
Type "help" for help.
[local:/run/pg13]:5130 pg13@dropdb=#

删除数据库,提示无法删除数据库

[pg13@localhost ~]$ psql
Expanded display is used automatically.
psql (13devel)
Type "help" for help.
[local:/run/pg13]:5130 pg13@masterdb=# drop database dropdb;
ERROR:  database "dropdb" is being accessed by other users
DETAIL:  There is 1 other session using the database.
[local:/run/pg13]:5130 pg13@masterdb=#

使用force选项删除

[local:/run/pg13]:5130 pg13@masterdb=# drop database dropdb with(force);
DROP DATABASE
[local:/run/pg13]:5130 pg13@masterdb=#

回到连接dropdb数据库的session,该session已被drop

[local:/run/pg13]:5130 pg13@dropdb=# select 1;
FATAL:  terminating connection due to administrator command
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
: @!>?

感谢各位的阅读,以上就是“PG 13提供的force选项有什么作用”的内容了,经过本文的学习后,相信大家对PG 13提供的force选项有什么作用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!

网页题目:PG13提供的force选项有什么作用
链接分享:https://www.cdcxhl.com/article28/pdeccp.html

成都网站建设公司_创新互联,为您提供小程序开发用户体验网站营销服务器托管网站收录微信公众号

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设