PostgreSQL Cluster Architecture (Nodes, Sharding, Streaming Replication, etc.)

Node and Cluster Architecture

PostgreSQL's cluster architecture refers to the interconnection of PostgreSQL database instances across multiple machines, forming a highly available and high-performance data management system. Each node in the cluster can handle identical read/write requests and exchange information with other nodes through some mechanism.

Master Node

The master node is responsible for accepting write requests and serves as the primary source of all data.

Replica Node

Replica nodes are responsible for receiving replication requests from the master node; they accept data sent by the master node and verify it at specific time intervals.

Sharding (Sharding)

Sharding refers to dividing a PostgreSQL database into several independent instances, where each instance manages only part of the data. This architectural approach can improve data processing efficiency and reliability while reducing pressure on individual machines.

Types of Sharding

There are two types of sharding:

  • horizontal sharding(水平分片):Distributes all application data across multiple nodes to increase processing capacity and reduce the risk of single-point failure.
  • vertical sharding(垂直分片):Scatters different parts of a table's data onto different nodes to meet performance requirements for various business needs.

Stream Replication (Stream Replication)

Stream replication refers to log files transmitted from the master node to replica nodes; after receiving these logs, each replica node provides real-time feedback to the master node until all logs are confirmed as received and applied. This method ensures that replica nodes maintain consistency with the master node.

Advantages

  • Enhances the reliability and availability of replica nodes.
  • Improves real-time data replication capabilities.

Partitioning (Partitioning)

Partitioning refers to dividing the data in PostgreSQL database tables according to specific rules, storing each part separately in different partitions. This approach can improve query efficiency and reduce storage space requirements.

Advantages

  • Enhances query performance.
  • Reduces storage space consumption.

Summary

PostgreSQL's cluster architecture involves interconnecting PostgreSQL database instances across multiple machines to form a highly available and high-performance data management system. Technologies such as sharding, stream replication, and partitioning can improve the efficiency and reliability of data processing while also reducing pressure and costs on individual machines.