Back to explorer
Databases & Storage 5 Min

PostgreSQL

MEDIUM

PostgreSQL (Relational Database Tuning)

PostgreSQL is an open-source object-relational database system offering transactional ACID guarantees and spatial indices.


1. Core Architecture

  • Write-Ahead Logging (WAL):

PostgreSQL writes modifications to the WAL on disk before updating actual data pages, ensuring durability in the event of crashes.

  • Indexes:
  • B-Tree: Default index for comparison queries (=, <, >).
  • GIN (Generalized Inverted Index): Indexes composite values (JSONB arrays, document text search).
  • GiST (Generalized Search Tree): Indexes spatial points (used by PostGIS extensions for geohash operations).

2. High-Availability & Replication

  • Synchronous Replication:

Transactions wait for logs to be written to both the primary and standby replicas before returning success, guaranteeing consistency at the cost of write latency.

  • Asynchronous Replication:

Transactions return success immediately after writing to the primary log, replicating changes to replicas with eventual consistency.


3. References & Tech Blogs

Capacity Calculator

Estimate QPS, bandwidth, and database sizing in real time based on active users and payload characteristics.

Daily Active Users (DAU)10M
Read Ratio vs Write Ratio90% / 10%
Payload Size (Bytes)500 B
Average Read QPS:521
Average Write QPS:58
Total Request QPS:579 req/s
Write Bandwidth:0.03 MB/s
Read Bandwidth:0.50 MB/s
Storage / Year:913 GB/yr