@ -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 )