title: Flask Python How to Single Folder Multiple DB Connection
body: <p>As we have multiple databases created for each customer, based on the session value of logged in customer, we are opening db connections in each and every function. Code as follows,</p>
  <pre><code>company_code = session['company_code']
  
  filename = main_dir_path+&quot;/&quot;+company_code+&quot;.txt&quot;
  fp = open(filename)
  for i, line in enumerate(fp):
  
      if i == 1:
          site_admin_db = line
  
      if i == 4:
          ams_db = line
  
  site_admin_db = site_admin_db.strip()
  ams_db = ams_db.strip()
  
  engine1 = create_engine('postgresql+psycopg2://username:pwd@host/'+site_admin_db)
  engine4 = create_engine('postgresql+psycopg2://username:pwd@host/'+ams_db)
  
  Base = declarative_base()
  Session1 = sessionmaker(bind=engine1)
  Session4 = sessionmaker(bind=engine4)
  
  sessions1 = Session1()
  sessions4 = Session4()
  </code></pre>
  <p>max connections in postgresql server is 100, psycopg2 - operational error - too many clients error is thrown.</p>
  <p>Whether increasing max connections value is good approach? or how to handle multiple db connections for different customer with single code folder.</p>