PostgreSQL.disconnect_database(database_name=None, verbose=False)[source]

Disconnect a database.

See also [DBMS-PS-DD-1].

  • database_name (str | None) – name of database to disconnect from; if database_name=None (default), disconnect the current database.

  • verbose (bool | int) – whether to print relevant information in console as the function runs, defaults to False


>>> from pyhelpers.dbms import PostgreSQL

>>> testdb = PostgreSQL('localhost', 5432, 'postgres', database_name='testdb')
Creating a database: "testdb" ... Done.
Password (postgres@localhost:5432): ***
Connecting postgres:***@localhost:5432/testdb ... Successfully.

>>> testdb.database_name

>>> testdb.disconnect_database()
>>> testdb.database_name

>>> # 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.