Module to provide Postgres compatibility to salt.
configuration: | In order to connect to Postgres, certain configuration is required in /etc/salt/minion on the relevant minions. Some sample configs might look like: postgres.host: 'localhost'
postgres.port: '5432'
postgres.user: 'postgres' -> db user
postgres.pass: ''
postgres.maintenance_db: 'postgres'
The default for the maintenance_db is 'postgres' and in most cases it can be left at the default setting. This data can also be passed into pillar. Options passed into opts will overwrite options passed into pillar |
---|---|
note: | This module uses MD5 hashing which may not be compliant with certain security audits. |
salt.modules.postgres.
available_extensions
(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶List available postgresql extensions
CLI Example:
salt '*' postgres.available_extensions
salt.modules.postgres.
create_extension
(name, if_not_exists=None, schema=None, ext_version=None, from_version=None, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Install a postgresql extension
CLI Example:
salt '*' postgres.create_extension 'adminpack'
salt.modules.postgres.
create_metadata
(name, ext_version=None, schema=None, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Get lifecycle information about an extension
CLI Example:
salt '*' postgres.create_metadata adminpack
salt.modules.postgres.
db_alter
(name, user=None, host=None, port=None, maintenance_db=None, password=None, tablespace=None, owner=None, owner_recurse=False, runas=None)¶Change tablespace or/and owner of database.
CLI Example:
salt '*' postgres.db_alter dbname owner=otheruser
salt.modules.postgres.
db_create
(name, user=None, host=None, port=None, maintenance_db=None, password=None, tablespace=None, encoding=None, lc_collate=None, lc_ctype=None, owner=None, template=None, runas=None)¶Adds a databases to the Postgres server.
CLI Example:
salt '*' postgres.db_create 'dbname'
salt '*' postgres.db_create 'dbname' template=template_postgis
salt.modules.postgres.
db_exists
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Checks if a database exists on the Postgres server.
CLI Example:
salt '*' postgres.db_exists 'dbname'
salt.modules.postgres.
db_list
(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Return dictionary with information about databases of a Postgres server.
CLI Example:
salt '*' postgres.db_list
salt.modules.postgres.
db_remove
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Removes a databases from the Postgres server.
CLI Example:
salt '*' postgres.db_remove 'dbname'
salt.modules.postgres.
drop_extension
(name, if_exists=None, restrict=None, cascade=None, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Drop an installed postgresql extension
CLI Example:
salt '*' postgres.drop_extension 'adminpack'
salt.modules.postgres.
get_available_extension
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Get info about an available postgresql extension
CLI Example:
salt '*' postgres.get_available_extension plpgsql
salt.modules.postgres.
get_installed_extension
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Get info about an installed postgresql extension
CLI Example:
salt '*' postgres.get_installed_extension plpgsql
salt.modules.postgres.
group_create
(groupname, user=None, host=None, port=None, maintenance_db=None, password=None, createdb=None, createuser=None, createroles=None, encrypted=None, login=None, inherit=None, superuser=None, replication=None, rolepassword=None, groups=None, runas=None)¶Creates a Postgres group. A group is postgres is similar to a user, but cannot login.
CLI Example:
salt '*' postgres.group_create 'groupname' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword'
salt.modules.postgres.
group_remove
(groupname, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Removes a group from the Postgres server.
CLI Example:
salt '*' postgres.group_remove 'groupname'
salt.modules.postgres.
group_update
(groupname, user=None, host=None, port=None, maintenance_db=None, password=None, createdb=None, createroles=None, createuser=None, encrypted=None, inherit=None, login=None, superuser=None, replication=None, rolepassword=None, groups=None, runas=None)¶Updates a postgres group
CLI Examples:
salt '*' postgres.group_update 'username' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword'
salt.modules.postgres.
installed_extensions
(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶List installed postgresql extensions
CLI Example:
salt '*' postgres.installed_extensions
salt.modules.postgres.
is_available_extension
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Test if a specific extension is available
CLI Example:
salt '*' postgres.is_available_extension
salt.modules.postgres.
is_installed_extension
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Test if a specific extension is installed
CLI Example:
salt '*' postgres.is_installed_extension
salt.modules.postgres.
owner_to
(dbname, ownername, user=None, host=None, port=None, password=None, runas=None)¶Set the owner of all schemas, functions, tables, views and sequences to the given username.
CLI Example:
salt '*' postgres.owner_to 'dbname' 'username'
salt.modules.postgres.
psql_query
(query, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Run an SQL-Query and return the results as a list. This command only supports SELECT statements. This limitation can be worked around with a query like this:
WITH updated AS (UPDATE pg_authid SET rolconnlimit = 2000 WHERE rolname = 'rolename' RETURNING rolconnlimit) SELECT * FROM updated;
CLI Example:
salt '*' postgres.psql_query 'select * from pg_stat_activity'
salt.modules.postgres.
role_get
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None, return_password=False)¶Return a dict with information about users of a Postgres server.
Set return_password to True to get password hash in the result.
CLI Example:
salt '*' postgres.role_get postgres
salt.modules.postgres.
schema_create
(dbname, name, owner=None, user=None, db_user=None, db_password=None, db_host=None, db_port=None)¶Creates a Postgres schema.
CLI Example:
salt '*' postgres.schema_create dbname name owner='owner' \
user='user' \
db_user='user' db_password='password'
db_host='hostname' db_port='port'
salt.modules.postgres.
schema_exists
(dbname, name, db_user=None, db_password=None, db_host=None, db_port=None)¶Checks if a schema exists on the Postgres server.
CLI Example:
salt '*' postgres.schema_exists dbname schemaname
salt.modules.postgres.
schema_get
(dbname, name, db_user=None, db_password=None, db_host=None, db_port=None)¶Return a dict with information about schemas in a database.
CLI Example:
salt '*' postgres.schema_get dbname name
salt.modules.postgres.
schema_list
(dbname, db_user=None, db_password=None, db_host=None, db_port=None)¶Return a dict with information about schemas in a Postgres database.
CLI Example:
salt '*' postgres.schema_list dbname
salt.modules.postgres.
schema_remove
(dbname, name, user=None, db_user=None, db_password=None, db_host=None, db_port=None)¶Removes a schema from the Postgres server.
CLI Example:
salt '*' postgres.schema_remove dbname schemaname
salt.modules.postgres.
tablespace_alter
(name, user=None, host=None, port=None, maintenance_db=None, password=None, new_name=None, new_owner=None, set_option=None, reset_option=None, runas=None)¶Change tablespace name, owner, or options. CLI Example: .. code-block:: bash
salt '*' postgres.tablespace_alter tsname new_owner=otheruser salt '*' postgres.tablespace_alter index_space new_name=fast_raid salt '*' postgres.tablespace_alter test set_option="{'seq_page_cost': '1.1'}" salt '*' postgres.tablespace_alter tsname reset_option=seq_page_cost
New in version Beryllium.
salt.modules.postgres.
tablespace_create
(name, location, options=None, owner=None, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Adds a tablespace to the Postgres server.
CLI Example:
salt '*' postgres.tablespace_create tablespacename '/path/datadir'
New in version Beryllium.
salt.modules.postgres.
tablespace_exists
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Checks if a tablespace exists on the Postgres server. CLI Example: .. code-block:: bash
salt '*' postgres.tablespace_exists 'dbname'
New in version Beryllium.
salt.modules.postgres.
tablespace_list
(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Return dictionary with information about tablespaces of a Postgres server. CLI Example: .. code-block:: bash
salt '*' postgres.tablespace_list
New in version Beryllium.
salt.modules.postgres.
tablespace_remove
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Removes a tablespace from the Postgres server. CLI Example: .. code-block:: bash
salt '*' postgres.tablespace_remove tsname
New in version Beryllium.
salt.modules.postgres.
user_create
(username, user=None, host=None, port=None, maintenance_db=None, password=None, createdb=None, createuser=None, createroles=None, inherit=None, login=None, connlimit=None, encrypted=None, superuser=None, replication=None, rolepassword=None, groups=None, runas=None)¶Creates a Postgres user.
CLI Examples:
salt '*' postgres.user_create 'username' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword'
salt.modules.postgres.
user_exists
(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Checks if a user exists on the Postgres server.
CLI Example:
salt '*' postgres.user_exists 'username'
salt.modules.postgres.
user_list
(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None, return_password=False)¶Return a dict with information about users of a Postgres server.
Set return_password to True to get password hash in the result.
CLI Example:
salt '*' postgres.user_list
salt.modules.postgres.
user_remove
(username, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Removes a user from the Postgres server.
CLI Example:
salt '*' postgres.user_remove 'username'
salt.modules.postgres.
user_update
(username, user=None, host=None, port=None, maintenance_db=None, password=None, createdb=None, createuser=None, createroles=None, encrypted=None, superuser=None, inherit=None, login=None, connlimit=None, replication=None, rolepassword=None, groups=None, runas=None)¶Updates a Postgres user.
CLI Examples:
salt '*' postgres.user_update 'username' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword'
salt.modules.postgres.
version
(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None)¶Return the version of a Postgres server.
CLI Example:
salt '*' postgres.version