postgresql_idx: improved doc, tests, remove useless lines from code (#55131)

* postgresql_idx: improve doc

* postgresql_idx: improve doc, removed unuseless rows from code

* postgresql_idx: misc doc fix

* postgresql_idx: moved common params where they were

* postgresql_idx: moved common params where they were 2
This commit is contained in:
Andrey Klychkov 2019-04-12 16:15:21 +03:00 committed by John R Barker
parent 6273574eb4
commit d790285e80
2 changed files with 21 additions and 11 deletions

View file

@ -18,8 +18,9 @@ DOCUMENTATION = r'''
module: postgresql_idx module: postgresql_idx
short_description: Create or drop indexes from a PostgreSQL database short_description: Create or drop indexes from a PostgreSQL database
description: description:
- Create or drop indexes from a PostgreSQL database - Create or drop indexes from a PostgreSQL database.
U(https://www.postgresql.org/docs/current/sql-createindex.html). - For more information see U(https://www.postgresql.org/docs/current/sql-createindex.html),
U(https://www.postgresql.org/docs/current/sql-dropindex.html).
version_added: '2.8' version_added: '2.8'
options: options:
@ -32,7 +33,7 @@ options:
- name - name
db: db:
description: description:
- Name of database where the index will be created/dropped. - Name of database to connect to and where the index will be created/dropped.
type: str type: str
aliases: aliases:
- login_db - login_db
@ -57,7 +58,8 @@ options:
type: str type: str
schema: schema:
description: description:
- Name of a database schema. - Name of a database schema where the index will be created.
type: str
login_password: login_password:
description: description:
- Password used to authenticate with PostgreSQL. - Password used to authenticate with PostgreSQL.
@ -90,6 +92,8 @@ options:
state: state:
description: description:
- Index state. - Index state.
- I(state=present) implies the index will be created if it does not exist.
- I(state=absent) implies the index will be dropped if it exists.
type: str type: str
default: present default: present
choices: [ absent, present ] choices: [ absent, present ]
@ -101,7 +105,7 @@ options:
required: true required: true
columns: columns:
description: description:
- List of index columns. - List of index columns that need to be covered by index.
- Mutually exclusive with I(state=absent). - Mutually exclusive with I(state=absent).
type: list type: list
aliases: aliases:
@ -121,6 +125,10 @@ options:
concurrent: concurrent:
description: description:
- Enable or disable concurrent mode (CREATE / DROP INDEX CONCURRENTLY). - Enable or disable concurrent mode (CREATE / DROP INDEX CONCURRENTLY).
- Pay attention, if I(concurrent=no), the table will be locked (ACCESS EXCLUSIVE) during the building process.
For more information about the lock levels see U(https://www.postgresql.org/docs/current/explicit-locking.html).
- If the building process was interrupted for any reason when I(cuncurrent=yes), the index becomes invalid.
In this case it should be dropped and created again.
- Mutually exclusive with I(cascade=yes). - Mutually exclusive with I(cascade=yes).
type: bool type: bool
default: yes default: yes
@ -145,6 +153,8 @@ options:
default: no default: no
notes: notes:
- The index building process can affect database performance.
- To avoid table locks on production databases, use I(concurrent=yes) (default behavior).
- The default authentication assumes that you are either logging in as or - The default authentication assumes that you are either logging in as or
sudo'ing to the postgres account on the host. sudo'ing to the postgres account on the host.
- This module uses psycopg2, a Python PostgreSQL database adapter. You must - This module uses psycopg2, a Python PostgreSQL database adapter. You must
@ -595,10 +605,7 @@ def main():
module.warn("Index %s is invalid! ROLLBACK" % idxname) module.warn("Index %s is invalid! ROLLBACK" % idxname)
if not concurrent: if not concurrent:
if module.check_mode: db_connection.commit()
db_connection.rollback()
else:
db_connection.commit()
kw['changed'] = changed kw['changed'] = changed
module.exit_json(**kw) module.exit_json(**kw)

View file

@ -181,6 +181,7 @@
storage_params: fillfactor=90 storage_params: fillfactor=90
register: result register: result
ignore_errors: yes ignore_errors: yes
when: tablespace.rc == 0
- assert: - assert:
that: that:
@ -267,6 +268,7 @@
check_mode: yes check_mode: yes
register: result register: result
ignore_errors: yes ignore_errors: yes
when: tablespace.rc == 0
- assert: - assert:
that: that:
@ -284,7 +286,7 @@
postgresql_query: postgresql_query:
db: postgres db: postgres
login_user: "{{ pg_user }}" login_user: "{{ pg_user }}"
query: "SELECT 1 FROM pg_indexes WHERE indexname = 'foo_test_idx'" query: "SELECT 1 FROM pg_indexes WHERE indexname = 'foo_test_idx' AND schemaname = 'foo'"
register: result register: result
when: tablespace.rc == 0 when: tablespace.rc == 0
@ -307,6 +309,7 @@
concurrent: no concurrent: no
register: result register: result
ignore_errors: yes ignore_errors: yes
when: tablespace.rc == 0
- assert: - assert:
that: that:
@ -324,7 +327,7 @@
postgresql_query: postgresql_query:
db: postgres db: postgres
login_user: "{{ pg_user }}" login_user: "{{ pg_user }}"
query: "SELECT 1 FROM pg_indexes WHERE indexname = 'foo_test_idx'" query: "SELECT 1 FROM pg_indexes WHERE indexname = 'foo_test_idx' and schemaname = 'foo'"
register: result register: result
when: tablespace.rc == 0 when: tablespace.rc == 0