From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Israel Brewster <israel@brewstersoft.com>
To: Sándor Daku <daku.sandor@gmail.com>
Cc: Christopher Browne <cbbrowne@gmail.com>
Cc: PostgreSQL Mailing Lists <pgsql-general@postgresql.org>
Subject: Re: Table partitioning for cloud service?
Date: Thu, 21 May 2020 15:05:24 -0700
Message-ID: <922ed62d-2ece-c6a0-6988-d7ad2f61a286@aklaver.com> (raw)
In-Reply-To: <D6DAD185-75E3-4022-A22D-6D7711E68FBA@brewstersoft.com>
References: <29ACFF1C-FF57-4A36-B3B4-F92C817D3AE8@brewstersoft.com>
<bbcaac9d-4da1-d087-c845-5580b6c7a709@aklaver.com>
<4F4DEDE2-7ABD-4652-99FE-70C435518AC3@brewstersoft.com>
<CAFNqd5XP0rZQoV4s-shdgunjhUur1pxc2HwJFM=4USAguMNpQw@mail.gmail.com>
<CAKyoTgYk+_QpsT40coRfx7HdFevZnNH-8o0yJAxWeJO_rNdQ_A@mail.gmail.com>
<D6DAD185-75E3-4022-A22D-6D7711E68FBA@brewstersoft.com>
On 5/21/20 1:23 PM, Israel Brewster wrote:
> On May 21, 2020, at 12:12 PM, Sándor Daku <daku.sandor@gmail.com
> <mailto:daku.sandor@gmail.com>> wrote:
>> Hi,
>>
>> On Thu, 21 May 2020 at 18:14, Christopher Browne <cbbrowne@gmail.com
>> <mailto:cbbrowne@gmail.com>> wrote:
>>
>> On Thu, 21 May 2020 at 11:53, Israel Brewster
>> <israel@brewstersoft.com <mailto:israel@brewstersoft.com>> 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 <http://www.brewstersoft.com/;
> Home of EZPunch and Lyrics Presenter
>>
>>
>> Regards,
>> Sándor
>>
>>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, israel@brewstersoft.com, daku.sandor@gmail.com, cbbrowne@gmail.com
Subject: Re: Table partitioning for cloud service?
In-Reply-To: <922ed62d-2ece-c6a0-6988-d7ad2f61a286@aklaver.com>
References: <29ACFF1C-FF57-4A36-B3B4-F92C817D3AE8@brewstersoft.com> <bbcaac9d-4da1-d087-c845-5580b6c7a709@aklaver.com> <4F4DEDE2-7ABD-4652-99FE-70C435518AC3@brewstersoft.com> <CAFNqd5XP0rZQoV4s-shdgunjhUur1pxc2HwJFM=4USAguMNpQw@mail.gmail.com> <CAKyoTgYk+_QpsT40coRfx7HdFevZnNH-8o0yJAxWeJO_rNdQ_A@mail.gmail.com> <D6DAD185-75E3-4022-A22D-6D7711E68FBA@brewstersoft.com> <922ed62d-2ece-c6a0-6988-d7ad2f61a286@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox