Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the purpose of the force option provided by PG 13

Shulou Source: shulou.com Published: 2022-05-31 15:24:13 10月26日 Update

This article mainly explains "what is the role of the force option provided by PG 13". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of the force option provided by PG 13"?

In PG 12 or below, you cannot delete a database if there is a connection. PG 13 provides the force option to terminate the connection and delete the database directly.

PG 12

Create a database and connect

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

Delete the database, waiting all the time, prompt after timeout

[pg12@localhost] $psqlExpanded 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 usersDETAIL: There is 1 other session using the database.

PG 13

Create a database and connect

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

Delete the database, indicating that the database cannot be deleted

[pg13@localhost ~] $psqlExpanded 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 usersDETAIL: There is 1 other session using the database. [local:/run/pg13]: 5130 pg13@masterdb=#

Delete using the force option

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

Back to the session that connects to the dropdb database, the session has been drop

[local:/run/pg13]: 5130 pg13@dropdb=# select 1: terminating connection due to administrator commandserver 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.: @! >? Thank you for your reading, the above is the content of "what is the role of force options provided by PG 13". After the study of this article, I believe you have a deeper understanding of the role of force options provided by PG 13, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data database function learning content tips that is ideas situations articles more versions knowledge knowledge points articles follow questions practice push research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Tech Info Microsoft NVidia Redmi