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
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 database tables using SQLAlchemy models
Returns a pretty formatted string of the database size.
Provides the full PostgreSQL URI string.
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 current version of QCFractal in the DB
upgrade
()Upgrade the database schema using the latest alembic revision.
Methods Documentation
-
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
-
database_uri
() → str[source]¶ Provides the full PostgreSQL URI string.
- Returns
The database URI
- Return type
str
-
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.
-