Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The PostgreSQL Database Is Too Big

A large number of “Delete” or “Update” operations carried out on the table may lead to a so-called ‘index bloat’. The problem occurs in indexes based on B-trees and consists in the appearance of many empty or almost empty pages in the index. Such a ‘bloating’ results in an increased size of the database and decreases its efficiency; the efficiency may even fall below the acceptable threshold. The solution is to reconstruct the index in accordance with the information given in the PostgreSQL documentation.

...

Duża liczba operacji DELETE czy UPDATE wykonywanych na tabeli może prowadzić do wystąpienia tzw. "index bloat". Problem występuje w indeksach opartych na B-drzewach i polega na tym, że w indeksie występuje wiele pustych lub prawie pustych stron. Takie "nadmuchanie" indeksu skutkuje zwiększonym rozmiarem bazy danych i prowadzi do obniżenia jej wydajności nawet do nieakceptowalnego poziomu. Rozwiązaniem jest przebudowanie indeksu zgodnie z informacjami podanymi w dokumentacji PostgreSQL.

Przy sprawdzaniu rozmiaru tabel przed i po przebudowaniu indeksów pomocne mogą być poniższe zapytania SQL.

The following SQL queries may be helpful when checking the size of the table size before and after the reconstruction of indexes:

  • Giving the table size in bytesPodaje rozmiary tabel w bajtach:
Code Block
SELECT relpages * 8192 AS size_in_bytes, relname FROM pg_class 
WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public') 
ORDER BY size_in_bytes DESC LIMIT 10;
  • Podaje sumę rozmiarów 10 największych tabelGiving the sum of the sizes of 10 biggest tables:
Code Block
SELECT SUM(sizes.size_in_bytes) AS total_size_for_top_10_tables FROM (SELECT relpages * 8192 AS size_in_bytes, relname FROM pg_class 
WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public') ORDER BY size_in_bytes DESC LIMIT 10) AS sizes;
  • Podaje sumę rozmiarów wszystkich tabelGiving the sum of the sizes of all tables:
Code Block
SELECT SUM(sizes.size_in_bytes) AS total_size_for_all_tables FROM (SELECT relpages * 8192 AS size_in_bytes, relname FROM pg_class 
WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')) AS sizes;

...