Database/sql managing connection pool

We are building a multi tenant application in Go. For each client connection we must set the schema/db to use prior to any usage of the connection. The application need to make sure that the connection should not be used by other clients.

After reading the below discussion, it seems like the recommended approach would be to maintain a pool of *sql.DB connections.!topic/golang-dev/RWmOv4SYUmc

How are people handling this ? Any pointers ? is a connection pool.

What I would recommend depends on what RDMBS you use and how isolated each tenant is. If you use PostgreSQL and each tenant uses a different schema, then just prefix each query with the the schema name. If each tenant is a different database, then you would need to use a separate connection pool for each tenant.

If you just handle each tenant with a company number or similar, then just handle it in a query parameter.

Use a map[string]*sql.DB to store the different pools.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.