Documentation
PLEASE NOTE: This document applies to latest version and not to the latest stable release v2.21
Documentation for other releases can be found by using the version selector in the top right of any doc page.postgresql_db
Add or remove PostgreSQL databases.
Attributes
check_mode:
support: full
Parameters
| Parameter | Required | Type | Values | Description |
|---|---|---|---|---|
| name | true | string | Name of the database to add or remove. | |
| state | string | present absent dump restore |
The database state. | |
| owner | string | Name of the role to set as owner of the database. | ||
| template | string | Template used to create the database. | ||
| encoding | string | Encoding of the database. | ||
| lc_collate | string | Collation order (LC_COLLATE) to use in the database. | ||
| lc_ctype | string | Character classification (LC_CTYPE) to use in the database. | ||
| target | string | File to backup or restore database. | ||
| target_opts | string | Additional arguments to pass to pg_dump/psql during dump/restore. | ||
| login_host | string | Host running the database. | ||
| login_user | string | The username to authenticate with. | ||
| login_password | string | The password to authenticate with. | ||
| port | integer | Database port to connect to. | ||
| login_unix_socket | string | Path to a Unix domain socket for local connections. | ||
| ssl_mode | string | Disable SSL certificate verification. |
Examples
- name: Create a new database with name "myapp"
postgresql_db:
name: myapp
state: present
- name: Create a new database with owner and encoding
postgresql_db:
name: myapp
state: present
owner: appuser
encoding: UTF-8
- name: Dump database to a file
postgresql_db:
name: myapp
state: dump
target: /tmp/myapp.sql
- name: Dump database in custom format
postgresql_db:
name: myapp
state: dump
target: /tmp/myapp.dump
target_opts: "-Fc"
- name: Restore database from a file
postgresql_db:
name: myapp
state: restore
target: /tmp/myapp.sql
- name: Drop database
postgresql_db:
name: myapp
state: absent
- name: Connect to remote database
postgresql_db:
name: myapp
state: present
login_host: db.example.com
login_user: admin
login_password: secret
port: 5432