the neatest set here would be using pgbouncer for connection pooling:
default_pool_size = 4 would keep 4 permanent connections to the postgres, pooling your 36 to use one of four when session completes.
I'm recommending pooler, because whether the connection persists on server or not depends on whether you disconnect or not. also zombies would keep a connection, while your code would initiate new sessions.
in short - to run query you have to connect to a database as user. If you run on same session another transaction, you reuse the connection (if you did not disconnect). You have to explicitly disconnect to close the session. If you fail to do it, connection will stay on server (using one of
also from 9.6 on we have
idle_in_transaction_session_timeout, which kills transaction if its idla for longer then n period, which would help to fight against zombies.