这篇文章主要讲解了“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选项有什么作用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。