postgresql_table – Create, drop, or modify a PostgreSQL table¶
New in version 2.8.
Parameters¶
Notes¶
Note
- If you do not pass db parameter, tables will be created in the database named postgres.
- PostgreSQL allows to create columnless table, so columns param is optional.
- Unlogged tables are available from PostgreSQL server version 9.1.
- 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_sequence – Create, drop, or alter a PostgreSQL sequence
- The official documentation on the postgresql_sequence module.
- postgresql_info – Gather information about PostgreSQL servers
- The official documentation on the postgresql_info module.
- postgresql_tablespace – Add or remove PostgreSQL tablespaces from remote hosts
- The official documentation on the postgresql_tablespace module.
- postgresql_owner – Change an owner of PostgreSQL database object
- The official documentation on the postgresql_owner module.
- postgresql_privs – Grant or revoke privileges on PostgreSQL database objects
- The official documentation on the postgresql_privs module.
- postgresql_copy – Copy data between a file/program and a PostgreSQL table
- The official documentation on the postgresql_copy module.
- CREATE TABLE reference
- Complete reference of the CREATE TABLE command documentation.
- ALTER TABLE reference
- Complete reference of the ALTER TABLE command documentation.
- DROP TABLE reference
- Complete reference of the DROP TABLE command documentation.
- PostgreSQL data types
- Complete reference of the PostgreSQL data types documentation.
Examples¶
- name: Create tbl2 in the acme database with the DDL like tbl1 with testuser as an owner
postgresql_table:
db: acme
name: tbl2
like: tbl1
owner: testuser
- name: Create tbl2 in the acme database and tablespace ssd with the DDL like tbl1 including comments and indexes
postgresql_table:
db: acme
table: tbl2
like: tbl1
including: comments, indexes
tablespace: ssd
- name: Create test_table with several columns in ssd tablespace with fillfactor=10 and autovacuum_analyze_threshold=1
postgresql_table:
name: test_table
columns:
- id bigserial primary key
- num bigint
- stories text
tablespace: ssd
storage_params:
- fillfactor=10
- autovacuum_analyze_threshold=1
- name: Create an unlogged table in schema acme
postgresql_table:
name: acme.useless_data
columns: waste_id int
unlogged: true
- name: Rename table foo to bar
postgresql_table:
table: foo
rename: bar
- name: Rename table foo from schema acme to bar
postgresql_table:
name: acme.foo
rename: bar
- name: Set owner to someuser
postgresql_table:
name: foo
owner: someuser
- name: Change tablespace of foo table to new_tablespace and set owner to new_user
postgresql_table:
name: foo
tablespace: new_tablespace
owner: new_user
- name: Truncate table foo
postgresql_table:
name: foo
truncate: yes
- name: Drop table foo from schema acme
postgresql_table:
name: acme.foo
state: absent
- name: Drop table bar cascade
postgresql_table:
name: bar
state: absent
cascade: yes
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Status¶
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]
Authors¶
- Andrei Klychkov (@Andersson007)
Hint
If you notice any issues in this documentation, you can edit this document to improve it.