Heikki Linnakangas: Multi-threaded PostgreSQL? (PGConf.EU 2023)

PostgreSQL expert Heikki Linnakangas discusses the benefits of a multi-threaded architecture, including shared memory and better cache locality, and proposes a plan for making the transition, including annotated code and static analysis.

Key takeaways
  • Heikki Linnakangas thinks postgreSQL should move towards a multi-threaded architecture, citing the benefits of shared memory and better cache locality.
  • The existing multi-process architecture is painful to maintain and has made it difficult to implement certain features.
  • To make the transition, he believes that all global variables need to be annotated as session-local or thread-local.
  • The author thinks that the best way to do this is to have a mode where the GOC can be set in the config file, and then the code will automatically switch from multiple processes to multiple threads.
  • He also suggests that static analysis could be used to find global variables that need to be changed.
  • The author believes that some extension authors may struggle to make their code thread-safe, but thinks that annotated code will help.
  • Multithreading will also make it easier for extensors to share data between connections.
  • There may be some compatibility issues with older extensions, and he suggests that flags could be added to the control file to indicate which extensions are compatible with the new threading model.
  • He also warns that there may be unexpected problems and bugs that arise during the transition.