Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql_user module doesn't close db connection #431

Closed
boosterKRD opened this issue Mar 20, 2023 · 4 comments
Closed

postgresql_user module doesn't close db connection #431

boosterKRD opened this issue Mar 20, 2023 · 4 comments

Comments

@boosterKRD
Copy link
Contributor

boosterKRD commented Mar 20, 2023

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

  1. Create a list with 10 elements
  2. 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'

@Andersson007
Copy link
Collaborator

@boosterKRD hi, thanks for reporting the issue!
Would you like to add the lines yourself? Use this Quick start guide to get started.
What do you think? If no time/wish, please let us know.
Waiting for your feedback

@boosterKRD
Copy link
Contributor Author

boosterKRD commented Mar 21, 2023

@Andersson007 I implemented changes locally and tested-> all works fine.
I am just a DBA, not a programmer, but I will try to create the PR (but I can't give you 100%, give me one week)
Ultimately there is another one strange place in the code that could be changed (I will write more about it in PR)

@Andersson007
Copy link
Collaborator

@boosterKRD brilliant, thanks! Just a fyi: you'll see integration/unit tests mentioned in the guide. I don't think you need to add any tests in this particular case.

  1. Add the lines you mentioned in the description
  2. Add a changelog fragment so that users see the fix in collection's changelog.

@Andersson007
Copy link
Collaborator

closed via #436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants