Thread: Postgres schema having > 20,000 schemas

Postgres schema having > 20,000 schemas

From
Anand Muthukrishnan
Date:

Can a single Postgres database contain more than 20,000 schemas? What are the implications of such a database design.

I was reading about postgres schemas here - http://www.postgresql.org/docs/8.2/static/ddl-schemas.html and I'm planning to create one schema per account in my multi-tenant Ruby on Rails app. Each schema would have a set of tables to store data of the relevant account.

Each user/schema for all the features we offer, could have 50-60 tables.

Can postgres handle all of this without any hiccups, provided I allocate a large EC2 instance to host the database server ?

By experience if any one faced trouble with such number of schemas in postgres, they could share and i thought i can get more guidance to avoid such pitfalls.


Re: Postgres schema having > 20,000 schemas

From
Bruce Momjian
Date:
On Wed, Jul 24, 2013 at 04:41:07PM +0530, Anand Muthukrishnan wrote:
> Can a single Postgres database contain more than 20,000 schemas? What are the
> implications of such a database design.
>
> I was reading about postgres schemas here - http://www.postgresql.org/docs/8.2/
> static/ddl-schemas.html and I'm planning to create one schema per account in my
> multi-tenant Ruby on Rails app. Each schema would have a set of tables to store
> data of the relevant account.
>
> Each user/schema for all the features we offer, could have 50-60 tables.
>
> Can postgres handle all of this without any hiccups, provided I allocate a
> large EC2 instance to host the database server ?
>
> By experience if any one faced trouble with such number of schemas in postgres,
> they could share and i thought i can get more guidance to avoid such pitfalls.

Well, I think the big question is whether you want them all in the same
database (in separate schemas), or in their own databases.  You might
want to look at this:

    http://momjian.us/main/blogs/pgblog/2012.html#April_23_2012

We have done some work in improving performance for databases with many
table and many schemas.  Not sure about the 20k schema performance,
though.  You might need to just test it.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +


Re: Postgres schema having > 20,000 schemas

From
Elliot
Date:
Also, the "Billion Tables Project" mentions a few attempts at databases
with many tables (20k schemas at 50 tables per schema is one million
tables). The presentation page is here
http://www.pgcon.org/2013/schedule/events/595.en.html

On 2013-07-24 10:21, Bruce Momjian wrote:
> On Wed, Jul 24, 2013 at 04:41:07PM +0530, Anand Muthukrishnan wrote:
>> Can a single Postgres database contain more than 20,000 schemas? What are the
>> implications of such a database design.
>>
>> I was reading about postgres schemas here - http://www.postgresql.org/docs/8.2/
>> static/ddl-schemas.html and I'm planning to create one schema per account in my
>> multi-tenant Ruby on Rails app. Each schema would have a set of tables to store
>> data of the relevant account.
>>
>> Each user/schema for all the features we offer, could have 50-60 tables.
>>
>> Can postgres handle all of this without any hiccups, provided I allocate a
>> large EC2 instance to host the database server ?
>>
>> By experience if any one faced trouble with such number of schemas in postgres,
>> they could share and i thought i can get more guidance to avoid such pitfalls.
> Well, I think the big question is whether you want them all in the same
> database (in separate schemas), or in their own databases.  You might
> want to look at this:
>
>     http://momjian.us/main/blogs/pgblog/2012.html#April_23_2012
>
> We have done some work in improving performance for databases with many
> table and many schemas.  Not sure about the 20k schema performance,
> though.  You might need to just test it.
>



Re: Postgres schema having > 20,000 schemas

From
Anand Muthukrishnan
Date:
We want them all in one Database.

Multi database architecture is giving high amount of overhead during database migrations and database connection
pooling.So we are evaluating single db with multi schema approach.  

Also, is there any hard limit on number of schemas and tables that can be present in one postgres database?



Sent from my iPhone

On 24-Jul-2013, at 7:51 PM, Bruce Momjian <bruce@momjian.us> wrote:

> On Wed, Jul 24, 2013 at 04:41:07PM +0530, Anand Muthukrishnan wrote:
>> Can a single Postgres database contain more than 20,000 schemas? What are the
>> implications of such a database design.
>>
>> I was reading about postgres schemas here - http://www.postgresql.org/docs/8.2/
>> static/ddl-schemas.html and I'm planning to create one schema per account in my
>> multi-tenant Ruby on Rails app. Each schema would have a set of tables to store
>> data of the relevant account.
>>
>> Each user/schema for all the features we offer, could have 50-60 tables.
>>
>> Can postgres handle all of this without any hiccups, provided I allocate a
>> large EC2 instance to host the database server ?
>>
>> By experience if any one faced trouble with such number of schemas in postgres,
>> they could share and i thought i can get more guidance to avoid such pitfalls.
>
> Well, I think the big question is whether you want them all in the same
> database (in separate schemas), or in their own databases.  You might
> want to look at this:
>
>    http://momjian.us/main/blogs/pgblog/2012.html#April_23_2012
>
> We have done some work in improving performance for databases with many
> table and many schemas.  Not sure about the 20k schema performance,
> though.  You might need to just test it.
>
> --
>  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>  EnterpriseDB                             http://enterprisedb.com
>
>  + It's impossible for everything to be true. +


Re: Postgres schema having > 20,000 schemas

From
Bruce Momjian
Date:
On Wed, Jul 24, 2013 at 11:38:05PM +0530, Anand Muthukrishnan wrote:
> We want them all in one Database.
>
> Multi database architecture is giving high amount of overhead during database migrations and database connection
pooling.So we are evaluating single db with multi schema approach.  
>
> Also, is there any hard limit on number of schemas and tables that can be present in one postgres database?

Not really, unless you start getting into the 100M count.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +