PostgreSQL.get_database_size

PostgreSQL.get_database_size(database_name=None)[source]

Retrieve the size of a database.

Parameters:

database_name (str | None) – Name of the database. If database_name=None (default), it retrieves the size of the currently-connected database.

Returns:

Size of the database.

Return type:

str

Examples:

>>> from pyhelpers.dbms import PostgreSQL
>>> testdb = PostgreSQL(database_name='testdb', verbose=True)
Password (postgres@localhost:5432): ***
Creating a database: "testdb" ... Done.
Connecting postgres:***@localhost:5432/testdb ... Successfully.
>>> testdb.get_database_size()
'7900 kB'
>>> testdb.DEFAULT_DATABASE
'postgres'
>>> testdb.get_database_size(database_name=testdb.DEFAULT_DATABASE)
'7828 kB'
>>> testdb.drop_database(verbose=True)  # Delete the database "testdb"
To drop the database "testdb" from postgres:***@localhost:5432
? [No]|Yes: yes
Dropping "testdb" ... Done.