Skip to content
Search

Pg-status

lastmod 2026-01-31created 2026-01-311 edits

Lightweight microservice for checking PostgreSQL host status

About

  • Sidecar-style microservice designed to detect the state of a PostgreSQL cluster in real time
  • Instantly check whether a host is alive, whether it is a master or a replica, and replica lag
  • Lightweight, high-performance design: about 9MiB of memory usage, low CPU load per request, handles up to 9000 requests per second
  • All data is served from memory, minimizing request latency
  • Periodically polls PostgreSQL host status in the background and exposes the results through an HTTP API (Plain/JSON responses)
  • Main API endpoints
    • /master: returns the current master host
    • /replica: returns a replica selected with a round-robin algorithm
    • /sync_by_time, /sync_by_bytes: returns a replica based on synchronization status measured in time or bytes
    • /hosts: status list of all hosts (JSON)
    • /status: detailed status of a specific host
  • Environment variable-based configuration : fine-grained control over connection timeout, allowed lag limit, polling interval, and more
  • Lock-free design with a single writer and multiple readers, for fast read responses and up-to-date data
    • Optimizes response speed at the cost of possible temporary data inconsistency
  • Logs service start/stop and state change events to stdout/stderr, showing failover, recovery, and synchronization state changes in real time
  • Master-replica switchover scenarios can be simulated using a proxy

See also

Favorite site

author Zer0 sitemap