Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL: What is the maximum number of tables can store in postgreSQL database?

Tags:

Q1: What is the maximum number of tables can store in database?

Q2: What is the maximum number of tables can union in view?

like image 652
Sarfaraz Makandar Avatar asked Mar 14 '14 04:03

Sarfaraz Makandar


People also ask

Can Postgres handle 1 billion rows?

As commercial database vendors are bragging about their capabilities we decided to push PostgreSQL to the next level and exceed 1 billion rows per second to show what we can do with Open Source. To those who need even more: 1 billion rows is by far not the limit - a lot more is possible.

What is the maximum number of tables that can be listed within a schema?

there are no maximums as far as numbers of tables go. however, a schema design that has 100,000 tables would be something I would seriously question.

Can Postgres handle terabytes of data?

There are active PostgreSQL clusters in production environments that manage many terabytes of data, and specialized systems that manage petabytes.


2 Answers

Q1: There's no explicit limit in the docs. In practice, some operations are O(n) on number of tables; expect planning times to increase, and problems with things like autovacuum as you get to many thousands or tens of thousands of tables in a database.

Q2: It depends on the query. Generally, huge unions are a bad idea. Table inheritance will work a little better, but if you're using constraint_exclusion will result in greatly increased planning times.

Both these questions suggest an underlying problem with your design. You shouldn't need massive numbers of tables, and giant unions.

Going by the comment in the other answer, you should really just be creating a few tables. You seem to want to create one table per phone number, which is nonsensical, and to create views per number on top of that. Do not do this, it's mismodelling the data and will make it harder, not easier, to work with. Indexes, where clauses, and joins will allow you to use the data more effectively when it's logically structured into a few tables. I suggest studying basic relational modelling.

If you run into scalability issues later, you can look at partitioning, but you won't need thousands of tables for that.

like image 98
Craig Ringer Avatar answered Sep 29 '22 19:09

Craig Ringer


Both are, in a practical sense, without limit.

The number of tables a database can hold is restricted by the space on your disk system. However, having a database with more than a few thousand tables is probably more an expression of an incorrect analysis of your application domain. Same goes for unions: if you have to union more than a handful of tables you probably should look at your table structure.

One practical scenario where this can happen is with Postgis: having many tables with similar attributes that could be joined in a single view (this is a flaw in the design of Postgis IMHO), but that would typically be handled at the application side (e.g. a GIS).

Can you explain your scenario where you would need a very large number of tables that need to be queried in one sweep?

like image 38
Patrick Avatar answered Sep 29 '22 19:09

Patrick