Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jiBcB-0005R3-2A for pgsql-general@arkaria.postgresql.org; Mon, 08 Jun 2020 06:50:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jiBc9-0000Hx-Mc for pgsql-general@arkaria.postgresql.org; Mon, 08 Jun 2020 06:50:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jiBc9-0000HP-9h for pgsql-general@lists.postgresql.org; Mon, 08 Jun 2020 06:50:33 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jiBc6-0001vu-Jf for pgsql-general@postgresql.org; Mon, 08 Jun 2020 06:50:32 +0000 Received: by mail-ej1-x62d.google.com with SMTP id n21so2549690ejg.3 for ; Sun, 07 Jun 2020 23:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=3TWes+7CLUGgE3HR97//abTJ3RZCujF6AYN4pHa+5jc=; b=U26PBDQ8QtSfph3gPEERJYpBu0yoWGEViTSA3wZu2Q1uyifPqB+FxQTkWyN3rhhYrh kUpTLhf8Jtp0CpVVzzLCer1hBuaeFcnGpT92w+13HtEjtgGT9wlm04CSEHiQSuXDWynL NN3lL44xVGkNVb6FU0Rjl72s1red+LBxHVA2rBO/EoFYMTqGMJyQs23JBFgRHSKJSXmC 2mu6oUs8j4kCtQi2Y/9jaMEQ6nLOm54Jx09tEv6igDusMZaEQZ6Ro4cKg3tXFurAV21P VCgYFQB474xpp3k83QAfbKcHpdILMWrwbKgB3Q6L45xRdFnI5n9d7ihYz0pueghL0HCi n1rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=3TWes+7CLUGgE3HR97//abTJ3RZCujF6AYN4pHa+5jc=; b=PiLnMzxU5wDAUE2btO6Z/M5c22EC4q85o4SC601CIXtQb5kLuVYONv6AcLqw6YOLfc HGjVAGv6eqcPusuzRrMRYddmEVBsaSuOAZKn9oi1Eirezd20WVkxL2jpxLXGNnTeo2g8 sRFZqEk7RzhwjQ23cs1EEX81Ck2VR55fTgWh2AgDiAE1kPirnEhU8sD9IV6F5wqq1FiG jtlxWOlNhvL5bX4UxI7ttW1hUaZCEftebaTyA1odqcfEJxVDFrFMcCgAcwIDZmIC1TCk nVdUVtHn5N1a8fGehe6NBzn46aSj0wwolMqzJq6zY4AIpVYbG1LPRasQMx5ISM/P/8Gn sFNA== X-Gm-Message-State: AOAM530SX2lfOqOi3FzSYv4kHfFsMh+e9wl6uoemfnlf8bTMo3naBGB6 PF6YaFx/kheHzUbjmUY1Mkghig== X-Google-Smtp-Source: ABdhPJyV7db74DZCOQpts8Rp0sOQTXZ1BaS/2FOiXhdFKLYTq7X7GQ2u8gRUy6PHKc2c6+xm/tMP6A== X-Received: by 2002:a17:906:b55:: with SMTP id v21mr18473529ejg.298.1591599028206; Sun, 07 Jun 2020 23:50:28 -0700 (PDT) Received: from localhost.localdomain (217-149-169-181.nat.highway.telekom.at. [217.149.169.181]) by smtp.gmail.com with ESMTPSA id bs16sm10106101ejb.39.2020.06.07.23.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jun 2020 23:50:27 -0700 (PDT) Message-ID: <43da42b535a4ce44c38c576cfd3c470f66e8e1d2.camel@cybertec.at> Subject: Re: Multitenent architecture From: Laurenz Albe To: Vasu Madhineni , Rob Sargent Cc: pgsql-general@postgresql.org Date: Mon, 08 Jun 2020 08:50:27 +0200 In-Reply-To: References: <45AB91CB-EFBF-40A6-9920-D757AA7F159D@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, 2020-06-06 at 11:56 +0800, Vasu Madhineni wrote: > > > On Fri, Jun 5, 2020 at 2:57 PM Laurenz Albe wrote: > > > > On Thu, 2020-06-04 at 23:52 +0800, Vasu Madhineni wrote: > > > > > We are planning a POC on multitenant architecture in Postgres, Could you please > > > > > help us with steps for multitenant using schema for each application model. > > > > > > > > For few tenants, you can keep identical tables in several schemas and > > > > set "search_path" to select a tenant. > > > > > > > > With many tenants, you are better off with one table that holds the > > > > data for all clients. You can use Row Level Security to have each > > > > tenant see only his or her data, and it might be a good idea to > > > > use list partitioning on the tenant ID. > > Our environment is medical clinical data, so each clinic as a tenant. > Approximately 500+ tenants with 6TB data. The important number to base this decision on would be the number of tables you'd expect in the database. It shouldn't be too many. If the database grows large, you may be better off sharding the database together with partitioning it across schemas. Several smaller databases are easier to back up and make scaling easier. Of course that requires your application to be part of the solution: it needs to know which database to use for which tenant. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com