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

connection to database don't close #24

Open
Marcellino-Palerme opened this issue Dec 15, 2023 · 4 comments
Open

connection to database don't close #24

Marcellino-Palerme opened this issue Dec 15, 2023 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Marcellino-Palerme
Copy link
Collaborator

connection to database don't close

Error message in container ep2m2-web:

[nuxt] [request error] [unhandled] [500] sorry, too many clients already

Reproduction:

  1. Start web site
  2. Use it several time
    => impossible to open web site
@Marcellino-Palerme Marcellino-Palerme added the bug Something isn't working label Dec 15, 2023
@Marcellino-Palerme Marcellino-Palerme added this to the 0.1.1 milestone Dec 15, 2023
@Marcellino-Palerme Marcellino-Palerme self-assigned this Dec 15, 2023
Marcellino-Palerme added a commit that referenced this issue Dec 18, 2023
Marcellino-Palerme added a commit that referenced this issue Dec 27, 2023
@Marcellino-Palerme
Copy link
Collaborator Author

It have to use promise for each connection to database with a catch and finally with client.close()

@Marcellino-Palerme
Copy link
Collaborator Author

Marcellino-Palerme commented Aug 28, 2024

Quick Fix : Every day restart container database or when we have a error or when number of connection is high

@Marcellino-Palerme
Copy link
Collaborator Author

Restart container: It's only if container stop or Docker service restart.
That mean we need to ask container stop itself.

Another idea, it's ask postgres to delete all connection inactive.
=> In postgres we see that with table pg_stat_activity and function pg_terminate_backend
Sample provide by chatGpt

CREATE OR REPLACE FUNCTION kill_idle_connections()
RETURNS void AS $$
DECLARE
    r RECORD;
BEGIN
    FOR r IN
        SELECT pid, state
        FROM pg_stat_activity
        WHERE state = 'idle'
        ORDER BY query_start ASC
        LIMIT 5 -- Limite le nombre de connexions à tuer à la fois
    LOOP
        EXECUTE 'SELECT pg_terminate_backend(' || r.pid || ');';
    END LOOP;
END;
$$ LANGUAGE plpgsql;

Maybe launch this function every connection ?

@Marcellino-Palerme
Copy link
Collaborator Author

TODO: Modify all case called database to use Pool instead of Client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant