Hi,
I am working on a web app that includes a web form and interactive, some real time, data-plots that allows both read and write of Postgresql database. I am using pyscodb2 for interfacing with the database.
All the examples I saw makes new connection with the database (and mostly sqlite examples) for every new transaction. However, connecting is an expensive overhead for Postgresql. psycodb2 provides a connection pool class which helps to avoid the overhead associated with connecting (psycopg2.pool – Connections pooling — Psycopg 2.9.1 documentation). Despite all the warnings agains using globals in Dash scripts, it seems that this is a case where I should use a global to store a persistent connection object. Can you provide code example that shows how to properly keep a persistent database connection in a Dash app? Thanks.
3 Likes
Anyone have ideas on this?
I have used psql connection pools with success in Dash. As I understand, this is indeed the way to go.
Hi Emil, can you give a small code example / structure for a multipage app in implementing this?