postgresql_db – Add or remove PostgreSQL databases from a remote host
postgresql_db – Add or remove PostgreSQL databases from a remote host
Synopsis
- Add or remove PostgreSQL databases from a remote host.
Requirements
The below requirements are needed on the host that executes this module.
- psycopg2
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
ca_cert string |
Specifies the name of a file containing SSL certificate authority (CA) certificate(s). If the file exists, the server's certificate will be verified to be signed by one of these authorities.
| |
conn_limit string added in 2.8 |
Specifies the database connection limit. | |
encoding string |
Encoding of the database | |
lc_collate string |
Collation order (LC_COLLATE) to use in the database. Must match collation order of template database unless | |
lc_ctype string |
Character classification (LC_CTYPE) to use in the database (e.g. lower, upper, ...) Must match LC_CTYPE of template database unless | |
login_host string |
Host running the database. | |
login_password string |
The password used to authenticate with. | |
login_unix_socket string |
Path to a Unix domain socket for local connections. | |
login_user string |
Default: "postgres" |
The username used to authenticate with. |
maintenance_db string added in 2.5 |
Default: "postgres" |
The value specifies the initial database (which is also called as maintenance DB) that Ansible connects to. |
name string / required |
Name of the database to add or remove
| |
owner string |
Name of the role to set as owner of the database | |
port integer |
Default: 5432 |
Database port to connect (if needed)
|
session_role string added in 2.8 |
Switch to session_role after connecting. The specified session_role must be a role that the current login_user is a member of. Permissions checking for SQL commands is carried out as though the session_role were the one that had logged in originally. | |
ssl_mode string |
|
Determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server. See https://www.postgresql.org/docs/current/static/libpq-ssl.html for more information on the modes. Default of |
state string |
|
The database state.
The format of the backup will be detected based on the target name. Supported compression formats for dump and restore include Supported formats for dump and restore include |
target path added in 2.4 |
File to back up or restore from. Used when state is | |
target_opts string added in 2.4 |
Further arguments for pg_dump or pg_restore. Used when state is | |
template string |
Template used to create the database |
Notes
Note
- State
dump
andrestore
don’t require psycopg2 since version 2.8. - The default authentication assumes that you are either logging in as or sudo’ing to the
postgres
account on the host. - This module uses psycopg2, a Python PostgreSQL database adapter. You must ensure that psycopg2 is installed on the host before using this module. If the remote host is the PostgreSQL server (which is the default case), then PostgreSQL must also be installed on the remote host. For Ubuntu-based systems, install the
postgresql
,libpq-dev
, andpython-psycopg2
packages on the remote host before using this module. - The ca_cert parameter requires at least Postgres version 8.4 and psycopg2 version 2.4.3.
Examples
- name: Create a new database with name "acme"
postgresql_db:
name: acme
# Note: If a template different from "template0" is specified, encoding and locale settings must match those of the template.
- name: Create a new database with name "acme" and specific encoding and locale # settings.
postgresql_db:
name: acme
encoding: UTF-8
lc_collate: de_DE.UTF-8
lc_ctype: de_DE.UTF-8
template: template0
# Note: Default limit for the number of concurrent connections to a specific database is "-1", which means "unlimited"
- name: Create a new database with name "acme" which has a limit of 100 concurrent connections
postgresql_db:
name: acme
conn_limit: "100"
- name: Dump an existing database to a file
postgresql_db:
name: acme
state: dump
target: /tmp/acme.sql
- name: Dump an existing database to a file (with compression)
postgresql_db:
name: acme
state: dump
target: /tmp/acme.sql.gz
- name: Dump a single schema for an existing database
postgresql_db:
name: acme
state: dump
target: /tmp/acme.sql
target_opts: "-n public"
Status
- This module is guaranteed to have no backward incompatible interface changes going forward. [stableinterface]
- This module is maintained by the Ansible Community. [community]
Authors
- Ansible Core Team
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.8/modules/postgresql_db_module.html