Posts

Showing posts with the label database scaling

Scaling strategies

Image
Introduction Scaling strategies in PostgreSQL are methods that help the database handle larger volumes of data, support high user concurrency and maintain high performance. These strategies are divided into the following main groups: In-Database Scaling First, you should choose Data & Structure Optimization solutions right within the Database , which saves resources and avoids incurring costs associated with upgrading hardware or purchasing additional servers. Table Partitioning Divide a massive table (hundreds of millions of rows) into smaller tables by Range, List, or Hash . Example: Divide the orders table by month. Postgres only needs to scan the exact partition containing the required data (Partition Pruning). Indexing : Use the correct index types such as B-Tree (default), GIN (for JSONB/Full-text search) and BRIN (for large time-series data) to accelerate query speeds. Vacuuming : Configure optimized Autovacuum to clean up Dead Tuples , avoiding Table Bloat that inflates d...

Using Table Partitioning Effectively

Image
Introduction In the previous article, we explored how to use table partitioning. However, you might have realized that we need to create partitions manually. This approach has limitations, including the difficulty of centralized management and the risk of missing partitions if data volume grows excessively large in the future (requiring additional partitions). Therefore, I will guide you on how to create and manage partitions effectively. Hash Partitioning Hash Partitioning operates by evenly distributing data into a fixed number of partitions right from the start using the MODULUS algorithm, which includes the following information: MODULUS (M) : The total fixed number of partitions into which you want to distribute the data. REMAINDER (R) : The identifying remainder for that specific partition (ranging from 0 to M - 1). The MODULUS algorithm works exactly as its name suggests by calculating the remainder. When inserting a record into the parent table: Postgres will use a hash funct...