-
Notifications
You must be signed in to change notification settings - Fork 112
Description
SUMMARY
There is no closing connection to DB in postgresql_user.py. Because of this, when using loops/with_items and etc, the number of connections is constantly growing until the loop ends or it becomes more than the DB connection-limit parameter (if there are more elements in the array, then users connection-limit )
ISSUE TYPE
- Bug Report
COMPONENT NAME
postgresql_user
EXPECTED RESULTS
After each iteration of the loop connection to DB must be closed as it is done in other modules (postgresql_membership, postgresql_query).
Two lines have to be added to
:cursor.close()
db_connection.close()
STEPS TO REPRODUCE
- Create a list with 10 elements
- run task and use select count(*) from pg_stat_activity where usename=your_user_db. "Pause: 5" will allow you to easily see how the number of connections grows and the closure of all connections occurs only after the end of the task
db_users:
-
{ username: 'test1', actions: 'LOGIN,INHERIT'}
...
... -
{ username: 'test10', actions: 'LOGIN,INHERIT'}
-
name: Create users
postgresql_user:
login_host: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
login_user: 'your_user_db'
db: 'postgres'
login_password: 'your_db_pass'
name: '{{ item.username }}'
password: 'md56771d07fa780767a22d0092372bd41ab'
role_attr_flags: '{{ item.actions }}'
conn_limit: '{{ item.conn_limit }}'
state: 'present'
with_list: '{{ db_users }}'
loop_control:
pause: 5
become_user: 'postgres'