- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# postgresql_slot – Add or remove replication slots from a PostgreSQL database

New in version 2.8.

- Synopsis

- Requirements

- Parameters

- Notes

- See Also

- Examples

- Return Values

- Status

## Synopsis

- Add or remove physical or logical replication slots from a PostgreSQL database.

## 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. aliases: ssl_rootcert
db string |  | Name of database to connect to. aliases: login_db
immediately_reserve boolean | Choices: no ← yes | Optional parameter that when `yes` specifies that the LSN for this replication slot be reserved immediately, otherwise the default, `no`, specifies that the LSN is reserved on the first connection from a streaming replication client. Is available from PostgreSQL version 9.6. Uses only with slot_type=physical. Mutually exclusive with slot_type=logical.
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.
name string / required |  | Name of the replication slot to add or remove. aliases: slot_name
output_plugin string | Default: "test_decoding" | All logical slots must indicate which output plugin decoder they're using. This parameter does not apply to physical slots. It will be ignored with slot_type=physical.
port integer | Default: 5432 | Database port to connect to. aliases: login_port
session_role string |  | 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.
slot_type string | Choices: logical physical ← | Slot type.
ssl_mode string | Choices: allow disable prefer ← require verify-ca verify-full | 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 `prefer` matches libpq default.
state string | Choices: absent present ← | The slot state. state=present implies the slot must be present in the system. state=absent implies the groups must be revoked from target_roles.

## Notes

Note

- Physical replication slots were introduced to PostgreSQL with version 9.4, while logical replication slots were added beginning with version 10.0.

- The default authentication assumes that you are either logging in as or sudo’ing to the `postgres` account on the host.

- To avoid “Peer authentication failed for user postgres” error, use postgres user as a become_user.

- 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, and python-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.

## See Also

See also

PostgreSQL pg_replication_slots view reference

  Complete reference of the PostgreSQL pg_replication_slots view.

PostgreSQL streaming replication protocol reference

  Complete reference of the PostgreSQL streaming replication protocol documentation.

PostgreSQL logical replication protocol reference

  Complete reference of the PostgreSQL logical replication protocol documentation.

## Examples

    - name: Create physical_one physical slot if doesn't exist
      become_user: postgres
      postgresql_slot:
        slot_name: physical_one
        db: ansible

    - name: Remove physical_one slot if exists
      become_user: postgres
      postgresql_slot:
        slot_name: physical_one
        db: ansible
        state: absent

    - name: Create logical_one logical slot to the database acme if doesn't exist
      postgresql_slot:
        name: logical_slot_one
        slot_type: logical
        state: present
        output_plugin: custom_decoder_one
        db: "acme"

    - name: Remove logical_one slot if exists from the cluster running on another host and non-standard port
      postgresql_slot:
        name: logical_one
        login_host: mydatabase.example.org
        port: 5433
        login_user: ourSuperuser
        login_password: thePassword
        state: absent

## Return Values

Common return values are documented here, the following are the fields unique to this module:

Key | Returned | Description
--- | --- | ---
name string | always | Name of the slot Sample: physical_one
queries string | always | List of executed queries. Sample: ["SELECT pg_create_physical_replication_slot('physical_one', False, False)"]

## Status

- This module is not guaranteed to have a backwards compatible interface. [preview]

- This module is maintained by the Ansible Community. [community]

### Authors

- John Scalia (@jscalia)

- Andrew Klychkov (@Andersson007)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.