IPC in PostgreSQL: Thomas Munro - PGCon 2023

Discover the ins and outs of IPC in PostgreSQL, including signal handling, latch functions, and best practices for async signal-safe handlers and Power management, from Thomas Munro at PGCon 2023.

Key takeaways
  • Never-ending bugs 🔒

  • IPC (Inter-Process Communication) issues in PostgreSQL: signal handling, incorrect usage can lead to bugs 💣

  • latch is an unusual word in Postgres (origin from system R, originally meant for mutexes) 🕊️

  • Signals can be blocked or unblocked by various means (e.g., sigstop, sigcont, sigtstp) ⏰

  • Window signals: emulate signals on Windows (e.g., poll, select, k-event, e-poll) 🚀

  • Real-time signals: not covered in this talk, but important for timely responses ⏰

  • Signal handlers must be async signal-safe 💯

  • Signal handlers should not be called from signal handlers 🚫

  • Postgres emulates signals on Windows to stabilize code (e.g., spinlocks, latches) ⛔️

  • Power management: efficient use of resources, energy management ⏯️

  • Atomic operations: for updating flags in distributed systems 🔩

  • Poll: superseded by e-poll and k-event on modern systems ⚡️

  • BPatches: bug fixes that directly target issues in signal handling ⚠️