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 1jbtJv-0003VD-QC for pgsql-general@arkaria.postgresql.org; Thu, 21 May 2020 22:05:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jbtJu-0006GD-LF for pgsql-general@arkaria.postgresql.org; Thu, 21 May 2020 22:05:42 +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 1jbtJt-0006G5-IN for pgsql-general@lists.postgresql.org; Thu, 21 May 2020 22:05:42 +0000 Received: from [66.111.4.25] (helo=out1-smtp.messagingengine.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jbtJp-0006Tk-Ii for pgsql-general@postgresql.org; Thu, 21 May 2020 22:05:41 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D21F85C0126; Thu, 21 May 2020 18:05:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 21 May 2020 18:05:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=W 4daYSY+1thDw29L51WgYpqgRsWcNzPmehi6s8z84OU=; b=NFlwi1YFFg9ZxV8WE dyaFLWnEPGP9u3+6rmCEWEYHgE5jU7S68Njrb6D9ZHNWzgQaSoZOlaPe5mh2nq4q aCmrwZNxHb/CyD66AQSb49FNYlA/XvLqPKpgWv9tALBW4n6qbaDtFkNMkpjUW/cR c0rFd8wFjvpBlSKYdh9X8/gq878Q7pbjpE/zTiGkPW+XQob5tNkLG0znzLlNImuj 71Q8KJRWhNqv6beE/ipS8VWXedKSMHcfOG997Z5zePuCbwJTthDQ45RCuYGi/z+R No08ofU159bhxQkS/OUoPDt9QIA4Oj6zw6Ip4sE7cejfZtMZeHCdq1ogFglKpF+U My6pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=W4daYSY+1thDw29L51WgYpqgRsWcNzPmehi6s8z84 OU=; b=InqV7rSLUKu6eCl1/QQUPomOOsKOatiCoTTwWVygWtXlxIMTZiDslmMSG l55q3NSnCg+XC5o44HnXSlZBCeVa1tzDsVNSHiXRqhKTEs1AL2M6CocatkCFvaNF 5BcdasviZhXwUMVowViuhQ1boh9JROJ38pWWejYSBDhlF7cgfFh0kkNH/AvAbI+w 0V9RzBmTiSOXv7/Hnt6dZL/NqnZKAGaFqGdIE3+7zmymVSa7sd2sdXkxZoqAV3lY SUeF/kZyBYG48WqcTSZEbQfLV7wpz7arDgbagBqEd5TBdURBE8W9h/dHMzhsjJrc DQ991VflU5R08bqA/P3ecFLF1L2OQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudduvddgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeehffdtgeelfedukeelkedvkeegieffhfdufeelueeh jeeuieduieevhefhfeegkeenucffohhmrghinhepshhqihhttghhrdhorhhgpdgsrhgvfi hsthgvrhhsohhfthdrtghomhenucfkphepjeehrddujedvrdehrddvfedunecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklh grvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 05FCA3280060; Thu, 21 May 2020 18:05:24 -0400 (EDT) Subject: Re: Table partitioning for cloud service? To: Israel Brewster , =?UTF-8?Q?S=c3=a1ndor_Daku?= Cc: Christopher Browne , PostgreSQL Mailing Lists References: <29ACFF1C-FF57-4A36-B3B4-F92C817D3AE8@brewstersoft.com> <4F4DEDE2-7ABD-4652-99FE-70C435518AC3@brewstersoft.com> From: Adrian Klaver Message-ID: <922ed62d-2ece-c6a0-6988-d7ad2f61a286@aklaver.com> Date: Thu, 21 May 2020 15:05:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 66.111.4.25 (deferred) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 5/21/20 1:23 PM, Israel Brewster wrote: > On May 21, 2020, at 12:12 PM, Sándor Daku > wrote: >> Hi, >> >> On Thu, 21 May 2020 at 18:14, Christopher Browne > > wrote: >> >> On Thu, 21 May 2020 at 11:53, Israel Brewster >> > wrote: >> >>> >> - Table-based tenancy (e.g. - each table has a "tenant_id" and >> queries need to specify the tenant) >> >> >> The database/schema per tenant solution can be tedious when you want >> to modify something on the structure and you have numerous tenants. >> Therefore I used the "tables with tenant_id" version in a similar >> situation but with a slight twist. One of the biggest issue of this >> solution is that if you forget to add the tenant_id to the where >> clause you are going to reveal one tenant's data to another. >> I came up with the solution that the database user have no privileges >> for accessing the base tables. Instead of that I generate views for >> each tenant and they can access their own data in the underlying table >> through these views. Now if forget to address the right tenant in my >> client code(it still happens sometimes) and try to directly access the >> base tables I get a strongly worded reminder from the server. > > Nice solution! I think I may go to something like that once I upgrade to > a cloud solution that lets me add multiple users to the DB (the free > tier of Heroku does not). In the meantime, while I just have the single > customer, I can fake it easily enough. > > Is there any shortcuts for referencing the proper views, or do you just > append/prepend something to every table reference in your SQL? One nice > thing about the database/schema approach is that I can just specify the > search_path (or database) in the connection command, and then all the > table references remain the same for all tenants. Also helps avoid the > situation you mentioned where you forget to address the right tenant, > since you only have to do it in one place. Of course, as you said, it > can be tedious when you want to modify the structure. I’ll have to think > about that a bit more. If you want to take the tedium out of it take a look at Sqitch: https://sqitch.org/ Then all you have to do is create the change once and deploy to the targets. > > --- > Israel Brewster > BrewsterSoft Development > http://www.brewstersoft.com > Home of EZPunch and Lyrics Presenter >> >> >> Regards, >> Sándor >> >> > -- Adrian Klaver adrian.klaver@aklaver.com