PostgreSQL – Guidelines for a Healthy Number of Tables in a PostgreSQL Schema

databaseperformancepostgispostgresqlschema-architecture

I manage a PostgreSQL + PostGIS database with two schemas of 200 and 120 tables.

I wonder if this is correct or I should organize the tables in more and smaller schemas.

So far, we hadn't had any problems of any kind with the database, despite the annoying scroll to get to the desired table in QGIS file explorer.

Best Answer

The way you structure your data should typically reflect the way you intend to use it.

If it’s the backend of an application and you need it to store transactional data, you would expect large numbers of tables as you want your schema to be normalized to avoid duplication across tables.

If you’re using it for analysis purposes (as hinted at with QGIS), it might be worth your time de-normalizing your schema into a smaller number of tables. You can Google for data warehousing, and star schema approaches for more on this.

Ultimately though, the variable you should be optimizing for is time. If it takes longer for you to restructure your database than the time it takes to write out complicated queries, IMHO stick with what you have.

Related Question