PostgreSQL.disconnect_database¶
- PostgreSQL.disconnect_database(database_name=None, verbose=False, raise_error=False)[source]¶
Disconnects from a database.
See also [DBMS-PS-DD-1].
- Parameters:
database_name (str | None) – Name of the database to disconnect from. If
database_name=None
(default), disconnect from the current database.verbose (bool | int) – Whether to print relevant information to the console; defaults to
False
.raise_error (bool) – Whether to raise the provided exception; if
raise_error=False
(default), the error will be suppressed.
Examples:
>>> from pyhelpers.dbms import PostgreSQL >>> testdb = PostgreSQL(database_name='testdb', verbose=True) Creating a database: "testdb" ... Done. Password (postgres@localhost:5432): *** Connecting postgres:***@localhost:5432/testdb ... Successfully. >>> testdb.database_name 'testdb' >>> testdb.disconnect_database() >>> testdb.database_name 'postgres' >>> # Delete the database "testdb" >>> testdb.drop_database(database_name='testdb', verbose=True) To drop the database "testdb" from postgres:***@localhost:5432 ? [No]|Yes: yes Dropping "testdb" ... Done.