community.postgresql.postgresql_sequence module – Create, drop, or alter a PostgreSQL sequence
Note
This module is part of the community.postgresql collection (version 1.7.4).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.postgresql
.
To use it in a playbook, specify: community.postgresql.postgresql_sequence
.
Parameters
Parameter |
Comments |
---|---|
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. |
|
Cache specifies how many sequence numbers are to be preallocated and stored in memory for faster access. The minimum value is 1 (only one value can be generated at a time, i.e., no cache), and this is also the default. |
|
Automatically drop objects that depend on the sequence, and in turn all objects that depend on those objects. Ignored if state=present. Only used with state=absent. Choices:
|
|
The cycle option allows the sequence to wrap around when the maxvalue or minvalue has been reached by an ascending or descending sequence respectively. If the limit is reached, the next number generated will be the minvalue or maxvalue, respectively. If Choices:
|
|
Specifies the data type of the sequence. Valid types are bigint, integer, and smallint. bigint is the default. The data type determines the default minimum and maximum values of the sequence. For more info see the documentation https://www.postgresql.org/docs/current/sql-createsequence.html. Supported from PostgreSQL 10. Choices:
|
|
Name of database to connect to and run queries against. |
|
Increment specifies which value is added to the current sequence value to create a new value. A positive value will make an ascending sequence, a negative one a descending sequence. The default value is 1. |
|
Host running the database. If you have connection issues when using |
|
The password this module should use to establish its PostgreSQL session. |
|
Path to a Unix domain socket for local connections. |
|
The username this module should use to establish its PostgreSQL session. Default: “postgres” |
|
Maxvalue determines the maximum value for the sequence. The default for an ascending sequence is the maximum value of the data type. The default for a descending sequence is -1. |
|
Minvalue determines the minimum value a sequence can generate. The default for an ascending sequence is 1. The default for a descending sequence is the minimum value of the data type. |
|
The new schema for the sequence. Will be used for moving a sequence to another schema. Works only for existing sequences. |
|
Set the owner for the sequence. |
|
Database port to connect to. Default: 5432 |
|
The new name for the sequence. Works only for existing sequences. |
|
The schema of the sequence. This is be used to create and relocate a sequence in the given schema. Default: “public” |
|
The name of the sequence. |
|
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. |
|
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 Choices:
|
|
Start allows the sequence to begin anywhere. The default starting value is minvalue for ascending sequences and maxvalue for descending ones. |
|
The sequence state. If state=absent other options will be ignored except of name and schema. Choices:
|
|
If It makes sense to use Choices:
|
Notes
Note
Supports
check_mode
.If you do not pass db parameter, sequence will be created in the database named postgres.
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
- community.postgresql.postgresql_table
The official documentation on the community.postgresql.postgresql_table module.
- community.postgresql.postgresql_owner
The official documentation on the community.postgresql.postgresql_owner module.
- community.postgresql.postgresql_privs
The official documentation on the community.postgresql.postgresql_privs module.
- community.postgresql.postgresql_tablespace
The official documentation on the community.postgresql.postgresql_tablespace module.
- CREATE SEQUENCE reference
Complete reference of the CREATE SEQUENCE command documentation.
- ALTER SEQUENCE reference
Complete reference of the ALTER SEQUENCE command documentation.
- DROP SEQUENCE reference
Complete reference of the DROP SEQUENCE command documentation.
Examples
- name: Create an ascending bigint sequence called foobar in the default
database
community.postgresql.postgresql_sequence:
name: foobar
- name: Create an ascending integer sequence called foobar, starting at 101
community.postgresql.postgresql_sequence:
name: foobar
data_type: integer
start: 101
- name: Create an descending sequence called foobar, starting at 101 and
preallocated 10 sequence numbers in cache
community.postgresql.postgresql_sequence:
name: foobar
increment: -1
cache: 10
start: 101
- name: Create an ascending sequence called foobar, which cycle between 1 to 10
community.postgresql.postgresql_sequence:
name: foobar
cycle: yes
min: 1
max: 10
- name: Create an ascending bigint sequence called foobar in the default
database with owner foobar
community.postgresql.postgresql_sequence:
name: foobar
owner: foobar
- name: Rename an existing sequence named foo to bar
community.postgresql.postgresql_sequence:
name: foo
rename_to: bar
- name: Change the schema of an existing sequence to foobar
community.postgresql.postgresql_sequence:
name: foobar
newschema: foobar
- name: Change the owner of an existing sequence to foobar
community.postgresql.postgresql_sequence:
name: foobar
owner: foobar
- name: Drop a sequence called foobar
community.postgresql.postgresql_sequence:
name: foobar
state: absent
- name: Drop a sequence called foobar with cascade
community.postgresql.postgresql_sequence:
name: foobar
cascade: yes
state: absent
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Shows if the sequence cycle or not. Returned: always Sample: “NO” |
|
Shows the current data type of the sequence. Returned: always Sample: “bigint” |
|
The value of increment of the sequence. A positive value will make an ascending sequence, a negative one a descending sequence. Returned: always Sample: “-1” |
|
The value of maxvalue of the sequence. Returned: always Sample: “9223372036854775807” |
|
The value of minvalue of the sequence. Returned: always Sample: “1” |
|
Shows the new sequence name after rename. Returned: on success Sample: “barfoo” |
|
Shows the new schema of the sequence after schema change. Returned: on success Sample: “foobar” |
|
Shows the current owner of the sequence after the successful run of the task. Returned: always Sample: “postgres” |
|
List of queries that was tried to be executed. Returned: always Sample: [“CREATE SEQUENCE \”foo\””] |
|
Name of the schema of the sequence. Returned: always Sample: “foo” |
|
Sequence name. Returned: always Sample: “foobar” |
|
The value of start of the sequence. Returned: always Sample: “12” |
|
Sequence state at the end of execution. Returned: always Sample: “present” |
Authors
Tobias Birkefeld (@tcraxs)
Thomas O’Donnell (@andytom)
Collection links
Issue Tracker Repository (Sources) Report an issue Communication