Module to provide Postgres compatibility to salt.
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
To prevent Postgres commands from running arbitrarily long, a timeout (in seconds) can be set
postgres.timeout: 60New in version 3006.0.
This module uses MD5 hashing which may not be compliant with certain security audits.
When installing postgres from the official postgres repos, on certain linux distributions, either the psql or the initdb binary is not automatically placed on the path. Add a configuration to the location of the postgres bin's path to the relevant minion for this module:
postgres.bins_dir: '/usr/pgsql-9.5/bin/'
List available postgresql extensions
CLI Example:
salt '*' postgres.available_extensions
Install a postgresql extension
CLI Example:
salt '*' postgres.create_extension 'adminpack'
Get lifecycle information about an extension
CLI Example:
salt '*' postgres.create_metadata adminpack
New in version 2016.3.0.
Checks if postgres data directory has been initialized
CLI Example:
salt '*' postgres.datadir_exists '/var/lib/pgsql/data'
Name of the directory to check
New in version 2016.3.0.
Initializes a postgres data directory
CLI Example:
salt '*' postgres.datadir_init '/var/lib/pgsql/data'
The name of the directory to initialize
The default authentication method for local connections
The password to set for the postgres user
The database superuser name
The default encoding for new databases
The default locale for new databases
The transaction log (WAL) directory (default is to keep WAL inside the data directory)
New in version 2019.2.0.
If True, the cluster will be created with data page checksums.
Note
Data page checksums are supported since PostgreSQL 9.3.
New in version 2019.2.0.
The system user the operation should be performed on behalf of
Change tablespace or/and owner of database.
CLI Example:
salt '*' postgres.db_alter dbname owner=otheruser
Adds a databases to the Postgres server.
CLI Example:
salt '*' postgres.db_create 'dbname'
salt '*' postgres.db_create 'dbname' template=template_postgis
Checks if a database exists on the Postgres server.
CLI Example:
salt '*' postgres.db_exists 'dbname'
Return dictionary with information about databases of a Postgres server.
CLI Example:
salt '*' postgres.db_list
Removes a databases from the Postgres server.
CLI Example:
salt '*' postgres.db_remove 'dbname'
Drop an installed postgresql extension
CLI Example:
salt '*' postgres.drop_extension 'adminpack'
Get info about an available postgresql extension
CLI Example:
salt '*' postgres.get_available_extension plpgsql
Get info about an installed postgresql extension
CLI Example:
salt '*' postgres.get_installed_extension plpgsql
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'
Removes a group from the Postgres server.
CLI Example:
salt '*' postgres.group_remove 'groupname'
Updates a postgres group
CLI Examples:
salt '*' postgres.group_update 'username' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword'
New in version 2016.3.0.
Check if a role has the specified privileges on an object
CLI Example:
salt '*' postgres.has_privileges user_name table_name table \
SELECT,INSERT maintenance_db=db_name
Name of the role whose privileges should be checked on object_type
Name of the object on which the check is to be performed
The object type, which can be one of the following:
table
sequence
schema
tablespace
language
database
group
function
Comma separated list of privileges to check, from the list below:
INSERT
CREATE
TRUNCATE
CONNECT
TRIGGER
SELECT
USAGE
TEMPORARY
UPDATE
EXECUTE
REFERENCES
DELETE
ALL
If grant_option is set to True, the grant option check is performed
Table and Sequence object types live under a schema so this should be provided if the object is not under the default public schema
The database to connect to
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
List installed postgresql extensions
CLI Example:
salt '*' postgres.installed_extensions
Test if a specific extension is available
CLI Example:
salt '*' postgres.is_available_extension
Test if a specific extension is installed
CLI Example:
salt '*' postgres.is_installed_extension
New in version 2016.3.0.
Installs a language into a database
CLI Example:
salt '*' postgres.language_create plpgsql dbname
Language to install
The database to install the language in
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
New in version 2016.3.0.
Checks if language exists in a database.
CLI Example:
salt '*' postgres.language_exists plpgsql dbname
Language to check for
The database to check in
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
New in version 2016.3.0.
Return a list of languages in a database.
CLI Example:
salt '*' postgres.language_list dbname
The database to check
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
New in version 2016.3.0.
Removes a language from a database
CLI Example:
salt '*' postgres.language_remove plpgsql dbname
Language to remove
The database to install the language in
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
Set the owner of all schemas, functions, tables, views and sequences to the given username.
CLI Example:
salt '*' postgres.owner_to 'dbname' 'username'
New in version 2016.3.0.
Grant privileges on a postgres object
CLI Example:
salt '*' postgres.privileges_grant user_name table_name table \
SELECT,UPDATE maintenance_db=db_name
Name of the role to which privileges should be granted
Name of the object on which the grant is to be performed
The object type, which can be one of the following:
table
sequence
schema
tablespace
language
database
group
function
Comma separated list of privileges to grant, from the list below:
INSERT
CREATE
TRUNCATE
CONNECT
TRIGGER
SELECT
USAGE
TEMPORARY
UPDATE
EXECUTE
REFERENCES
DELETE
ALL
If grant_option is set to True, the recipient of the privilege can in turn grant it to others
Table and Sequence object types live under a schema so this should be provided if the object is not under the default public schema
The database to connect to
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
New in version 2016.3.0.
Return a list of privileges for the specified object.
CLI Example:
salt '*' postgres.privileges_list table_name table maintenance_db=db_name
Name of the object for which the permissions should be returned
The object type, which can be one of the following:
table
sequence
schema
tablespace
language
database
group
function
Table and Sequence object types live under a schema so this should be provided if the object is not under the default public schema
The database to connect to
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
New in version 2016.3.0.
Revoke privileges on a postgres object
CLI Example:
salt '*' postgres.privileges_revoke user_name table_name table \
SELECT,UPDATE maintenance_db=db_name
Name of the role whose privileges should be revoked
Name of the object on which the revoke is to be performed
The object type, which can be one of the following:
table
sequence
schema
tablespace
language
database
group
function
Comma separated list of privileges to revoke, from the list below:
INSERT
CREATE
TRUNCATE
CONNECT
TRIGGER
SELECT
USAGE
TEMPORARY
UPDATE
EXECUTE
REFERENCES
DELETE
ALL
The database to connect to
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
System user all operations should be performed on behalf of
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;
The query string.
Database username, if different from config or default.
Database host, if different from config or default.
Database port, if different from the config or default.
The database to run the query against.
User password, if different from the config or default.
User to run the command as.
Mark query as READ WRITE transaction.
CLI Example:
salt '*' postgres.psql_query 'select * from pg_stat_activity'
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
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'
Checks if a schema exists on the Postgres server.
CLI Example:
salt '*' postgres.schema_exists dbname schemaname
Database name we query on
Schema name we look for
The system user the operation should be performed on behalf of
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
Return a dict with information about schemas in a database.
CLI Example:
salt '*' postgres.schema_get dbname name
Database name we query on
Schema name we look for
The system user the operation should be performed on behalf of
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
Return a dict with information about schemas in a Postgres database.
CLI Example:
salt '*' postgres.schema_list dbname
Database name we query on
The system user the operation should be performed on behalf of
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
Removes a schema from the Postgres server.
CLI Example:
salt '*' postgres.schema_remove dbname schemaname
Database name we work on
The schema's name we'll remove
System user all operations should be performed on behalf of
database username if different from config or default
user password if any password for a specified user
Database host if different from config or default
Database port if different from config or default
Change tablespace name, owner, or options.
CLI Example:
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 2015.8.0.
Adds a tablespace to the Postgres server.
CLI Example:
salt '*' postgres.tablespace_create tablespacename '/path/datadir'
New in version 2015.8.0.
Checks if a tablespace exists on the Postgres server.
CLI Example:
salt '*' postgres.tablespace_exists 'dbname'
New in version 2015.8.0.
Return dictionary with information about tablespaces of a Postgres server.
CLI Example:
salt '*' postgres.tablespace_list
New in version 2015.8.0.
Removes a tablespace from the Postgres server.
CLI Example:
salt '*' postgres.tablespace_remove tsname
New in version 2015.8.0.
Creates a Postgres user.
CLI Examples:
salt '*' postgres.user_create 'username' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword' valid_until='valid_until'
Checks if a user exists on the Postgres server.
CLI Example:
salt '*' postgres.user_exists 'username'
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
Removes a user from the Postgres server.
CLI Example:
salt '*' postgres.user_remove 'username'
Updates a Postgres user.
CLI Examples:
salt '*' postgres.user_update 'username' user='user' \
host='hostname' port='port' password='password' \
rolepassword='rolepassword' valid_until='valid_until'
Return the version of a Postgres server.
CLI Example:
salt '*' postgres.version