<div dir="ltr">Hi,<div><br></div><div>I'm hitting the default (100) `max_connection` PostgreSQL limit with ~4 users using a QGIS project with ~25 layers/tables. I know that I can raise the limit, but I'm trying to understand how QGIS handles database connections.</div><div><br></div><div>I didn't find so much information about it:</div><div><br></div><div><ol><li><a href="https://lists.osgeo.org/pipermail/qgis-developer/2008-March/003446.html">https://lists.osgeo.org/pipermail/qgis-developer/2008-March/003446.html</a>. Old post against, something like, an internal connection pool in QGIS</li><li><a href="https://github.com/qgis/QGIS/issues/30373">https://github.com/qgis/QGIS/issues/30373</a>. Feature request to share a single connection between different layers</li><li><a href="https://stackoverflow.com/a/71557537/930271">https://stackoverflow.com/a/71557537/930271</a> an ¿explanation? of how connection works in QGIS. I copy&paste here because this post may be hide for some users:</li></ol><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">for what I know every single layer creates at least one, possibly two, connections (one is read only the other one is read-write ), these two connections have the same lifetime of the layer, the read-write connection is created on-demand if a read-write operation is requested (editing/adding/deleting features). </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Multiple layers using the same DB connection will not share these two connections. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In addition to the two connections above, temporary connections are created from a connection pool when the features are fetched from the layer(s), these connections are pooled (shared) and released when the fetching is finished, there is also a timeout to close them after 60 seconds idle. </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">It would be useful to check PG logs and see in which state these connections are, from my tests, the read-only connection is kept in ClientRead | idle.</blockquote><div><br></div><div>So,</div><div><ul><li>Can someone confirm the previous quote, explain how QGIS handles connections, or point me to relevant code or doc?</li><li>An invisible/unchecked layer consumes a connection?</li><li>Does make sense a feature request about this topic. Maybe</li><ul><li>Reuse connection</li><li>a kind of internal pooling</li><li>a configurable user limit, so next database access will wait for other connections to close to start operations</li><li>...</li></ul></ul></div></div><div>Many thanks.</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Francisco Puga</div><div>iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.</div><div><a href="https://icarto.es/" target="_blank">https://icarto.es</a></div><div><br></div></div></div></div></div>