PostgresOSM.disconnect_database

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

Kill the connection to a database in the PostgreSQL server being connected.

If database_name is None (default), disconnect the current database.

Parameters
  • database_name (str or None) – name of database to disconnect from, defaults to None

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

Example:

>>> from pyhelpers.sql import PostgreSQL

>>> testdb = PostgreSQL('localhost', 5432, username='postgres', database_name='testdb')
Password (postgres@localhost:5432): ***
Connecting postgres:***@localhost:5432/testdb ... Successfully.

>>> print(testdb.database_name)
testdb

>>> testdb.disconnect_database()
>>> print(testdb.database_name)
postgres