|
|
|
|
|
by SigmundA
28 days ago
|
|
Each PG connection being a whole process does not scale like MSSQL that uses a thread per connection which has a max of 32k per instance. There are no need for connection poolers in front of MSSQL although it is normal to pool connections in the client application which may hold hundreds open typically in a web server. This also allows MSSQL to more easily share cached query plans between connections since its just sharing executable code between threads. For PG to do plan caching it would need to serialize the plan between processes and that would require some significant work since it was never designed that way. PG has it obvious unix roots using processes instead of threads, MSSQL coming from Windows where new process are expensive and there was no real fork, but threads are cheap uses that approach instead. |
|
There's no free lunch id think, the PG model is more robust. Unsafe extensions can take down the whole instance in the threaded model, processes contain the blast radius to that connection (also typically easier to debug since this type of issue is thankfully rare, it's also gnarly to get on top of).
Further, on linux (not on windows) a lot of the lines between a thread and a process get blurry (copy on write, shared memory mappings etc). They're both handled very similarly in the kernel, theyre both scheduled using similar machinery.
>> For PG to do plan caching it would need to serialize the plan between processes and that would require some significant work since it was never designed that way.
Is that true? I'm thinking the buffer cache and locks and WAL coordination are just as fast - it's just mmap'd SHM into each process. It's not like every access needs IPC?