1. A computer-implemented method for automatic allocation of tenants to a predetermined number of databases, the method comprising: determining, by a computer system, a query plan for each query template of each tenant, wherein said each query template comprises a set of queries associated with a restricted querying interface specific to a server among a plurality of servers to potentially house one or more of the predetermined number of databases, wherein the set of queries have restricted data access based on a tenant identifier; creating a distance metric based on the query plan for said each tenant; selecting the predetermined number of databases according to a total cost associated with said each tenant; and clustering the tenants based on the distance metric into a predetermined number of clusters which is equal to the predetermined number of databases.