wuttamess.postgres
¶
PostgreSQL DB utilities
- wuttamess.postgres.create_db(c, name, owner=None, port=None, checkfirst=True)[source]¶
Create a PostgreSQL database.
- Parameters:
c – Fabric connection.
name – Name of the database to create.
owner – Optional role name to set as owner for the database.
port – Optional port for PostgreSQL; default is 5432.
checkfirst – If true (the default), first check if DB exists and skip creating if already present. If false, then try to create DB with no check.
- wuttamess.postgres.create_user(c, name, password=None, port=None, checkfirst=True)[source]¶
Create a PostgreSQL user account.
- Parameters:
c – Fabric connection.
name – Username to create.
password – Optional password for the new user. If set, will call
set_user_password()
.port – Optional port for PostgreSQL; default is 5432.
checkfirst – If true (the default), first check if user exists and skip creating if already present. If false, then try to create user with no check.
- wuttamess.postgres.db_exists(c, name, port=None)[source]¶
Determine if a given PostgreSQL database exists.
- Parameters:
c – Fabric connection.
name – Name of the database to check for.
port – Optional port for PostgreSQL; default is 5432.
- Returns:
True
if database exists, elseFalse
.
- wuttamess.postgres.drop_db(c, name, checkfirst=True)[source]¶
Drop a PostgreSQL database.
- Parameters:
c – Fabric connection.
name – Name of the database to drop.
checkfirst – If true (the default), first check if DB exists and skip dropping if not present. If false, then try to drop DB with no check.
- wuttamess.postgres.dump_db(c, name)[source]¶
Dump a PostgreSQL database to file.
This uses the
pg_dump
andgzip
commands to produce a compressed SQL dump. The filename returned is based on thename
provided, e.g.mydbname.sql.gz
.- Parameters:
c – Fabric connection.
name – Name of the database to dump.
- Returns:
Base name of the output file. We only return the filename and not the path, since the file is expected to exist in the connected user’s home folder.
- wuttamess.postgres.set_user_password(c, name, password, port=None)[source]¶
Set the password for a PostgreSQL user account.
- Parameters:
c – Fabric connection.
name – Username whose password is to be set.
password – Password for the new user.
port – Optional port for PostgreSQL; default is 5432.
- wuttamess.postgres.sql(c, sql, database='', port=None, **kwargs)[source]¶
Execute some SQL as the
postgres
user.- Parameters:
c – Fabric connection.
sql – SQL string to execute.
database – Name of the database on which to execute the SQL. If not specified, default
postgres
is assumed.port – Optional port for PostgreSQL; default is 5432.