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.
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.