PostgreSQL.disconnect_database

PostgreSQL.disconnect_database(database_name=None, verbose=False)

Disconnect a database.

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

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

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

Examples:

>>> 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'

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