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 โš ๏ธ