Re: Threads - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Threads
Date
Msg-id 87isx0izwk.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: Threads  (Greg Copeland <greg@CopelandConsulting.Net>)
Responses Re: Threads  (Greg Copeland <greg@CopelandConsulting.Net>)
Re: Threads  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Greg Copeland <greg@CopelandConsulting.Net> writes:

> That's the power of using the process model that is currently in use. Should
> it do something naughty, we bitch and complain politely, throw our hands in
> the air and exit. We no longer have to worry about the state and validity of
> that backend.

You missed the point of his post. If one process in your database does
something nasty you damn well should worry about the state of and validity of
the entire database, not just that one backend.

Are you really sure you caught the problem before it screwed up the data in
shared memory? On disk?


This whole topic is in need of some serious FUD-dispelling and careful
analysis. Here's a more calm explanation of the situation on this particular
point. Perhaps I'll follow up with something on IO concurrency later.

The point in consideration here is really memory isolation. Threads by default
have zero isolation between threads. They can all access each other's memory
even including their stack. Most of that memory is in fact only needed by a
single thread. 

Processes by default have complete memory isolation. However postgres actually
weakens that by doing a lot of work in a shared memory pool. That memory gets
exactly the same protection as it would get in a threaded model, which is to
say none.

So the reality is that if you have a bug most likely you've only corrupted the
local data which can be easily cleaned up either way. In the thread model
there's also the unlikely but scary risk that you've damaged other threads'
memory. And in either case there's the possibility that you've damaged the
shared pool which is unrecoverable.

In theory minimising the one case of corrupting other threads' local data
shouldn't make a big difference to the risk in the case of an assertion
failure. I'm not sure in practice if that's true though. Processes probably
reduce the temptation to do work in the shared area too.

--
greg



pgsql-hackers by date:

Previous
From: Lamar Owen
Date:
Subject: Re: [GENERAL] Have people taken a look at pgdiff yet?
Next
From: Greg Copeland
Date:
Subject: Re: Threads