eqsql.db_tools module¶
- eqsql.db_tools.init_eqsql_db(db_path, create_db_sql_file=None, db_user='eqsql_user', db_name='EQ_SQL', db_port=None, pg_bin_path='')¶
Creates and initialized an EQSQL postgresql database.
- This will:
Create a database “cluster” at the specified path.
Start the server instance using that cluster.
Create the specified user.
Create the specified database in that cluster.
Populate that database with tables etc. by executing the commands in the specified file.
Stop the database server.
- Parameters:
db_path (str) – the file path for the database cluster. This must not exist.
create_db_sql_file (str | bytes | PathLike) – a file containing the SQL to execute to create the database tables etc. If this is None (the default) the default EQSQL SQL schema will be used.
db_user (str) – the database user name
db_name (str) – the name of the database
db_port – the port of the database server.
pg_bin_path (str | bytes | PathLike) – the path to postgresql’s bin directory (i.e. the directory that contains the pg_ctl, createuser and createdb executables)
- eqsql.db_tools.reset_db(db_user='eqsql_user', db_name='EQ_SQL', db_host='localhost', db_port=None, db_password=None)¶
Resets the database by deleting the contents of all the eqsql tables and restarting the emews task id generator sequence.
- Parameters:
db_user (str) – the database user name
db_name (str) – the name of the database
db_host (str) – the hostname where the database server is located
db_port (int) – the port of the database server.
db_password (str)
- eqsql.db_tools.start_db(db_path, pg_bin_path='', db_port=None)¶
Starts the postgresql database cluster on the specified path
- Parameters:
db_path (str | bytes | PathLike) – the file path for the database cluster to start
pg_bin_path (str | bytes | PathLike) – path to postgresql’s bin directory (i.e. the directory that contains the pg_ctl executable)
db_port (int) – the port number to start the db on
- eqsql.db_tools.stop_db(db_path, pg_bin_path='', db_port=None)¶
Stops the postgresql database cluster on the specified path
- Parameters:
db_path (str | bytes | PathLike) – the file path for the database cluster to stop
pg_bin_path (str | bytes | PathLike) – path to postgresql’s bin directory (i.e. the directory that contains the pg_ctl executable)
db_port (int) – the port number of the database to stop