PostgresHarness

class qcfractal.PostgresHarness(config: Union[Dict[str, Any], qcfractal.config.FractalConfig], quiet: bool = True, logger: print = <built-in function print>)[source]

Bases: object

Methods Summary

alembic_commands()

backup_database([filename])

command(cmd[, check])

Runs psql commands and returns their output while connected to the correct postgres instance.

connect([database])

Builds a psycopg2 connection object.

create_database(database_name)

Creates a new database for the current postgres instance.

create_tables()

Create database tables using SQLAlchemy models

database_size()

Returns a pretty formatted string of the database size.

database_uri()

Provides the full PostgreSQL URI string.

init_database()

initialize_postgres()

Initializes and starts the current postgres instance.

is_alive([database])

Checks if the postgres is alive, and optionally if the database is present.

logger(msg)

Prints a logging message depending on quiet settings.

pg_ctl(cmds)

Runs pg_ctl commands and returns their output while connected to the correct postgres instance.

restore_database(filename)

shutdown()

Shutsdown the current postgres instance.

start()

Starts a PostgreSQL server based off the current configuration parameters.

update_db_version()

Update current version of QCFractal in the DB

upgrade()

Upgrade the database schema using the latest alembic revision.

Methods Documentation

alembic_commands() → List[str][source]
backup_database(filename: Optional[str] = None) → None[source]
command(cmd: str, check: bool = True) → Any[source]

Runs psql commands and returns their output while connected to the correct postgres instance.

Parameters

cmd (str) – A psql command string. Description

connect(database: Optional[str] = None) → Connection[source]

Builds a psycopg2 connection object.

Parameters

database (Optional[str], optional) – The database to connect to, otherwise defaults to None

Returns

A live Connection object.

Return type

Connection

create_database(database_name: str) → bool[source]

Creates a new database for the current postgres instance. If the database is existing, no changes to the database are made.

Parameters

database_name (str) – The name of the database to create.

Returns

If the operation was successful or not.

Return type

bool

create_tables()[source]

Create database tables using SQLAlchemy models

database_size() → str[source]

Returns a pretty formatted string of the database size.

database_uri() → str[source]

Provides the full PostgreSQL URI string.

Returns

The database URI

Return type

str

init_database() → None[source]
initialize_postgres() → None[source]

Initializes and starts the current postgres instance.

is_alive(database: Optional[str] = None) → bool[source]

Checks if the postgres is alive, and optionally if the database is present.

Parameters

database (Optional[str], optional) – The datbase to connect to

Returns

If True, the postgres database is alive.

Return type

bool

logger(msg: str) → None[source]

Prints a logging message depending on quiet settings.

Parameters

msg (str) – The message to show.

pg_ctl(cmds: List[str]) → Any[source]

Runs pg_ctl commands and returns their output while connected to the correct postgres instance.

Parameters

cmds (List[str]) – A list of PostgreSQL pg_ctl commands to run.

restore_database(filename) → None[source]
shutdown() → Any[source]

Shutsdown the current postgres instance.

start() → Any[source]

Starts a PostgreSQL server based off the current configuration parameters. The server must be initialized and the configured port open.

update_db_version()[source]

Update current version of QCFractal in the DB

upgrade()[source]

Upgrade the database schema using the latest alembic revision. The database data won’t be deleted.