Re: Threads in PostgreSQL

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: Atri Sharma <atri(dot)jiit(at)gmail(dot)com>, sri harsha <sriharsha9992(at)gmail(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Threads in PostgreSQL
Date: 2015-12-21 07:00:53
Message-ID: 5677A3A5.2060200@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 12/21/15 01:24, Atri Sharma wrote:
> On Mon, Dec 21, 2015, sri harsha <sriharsha9992(at)gmail(dot)com> wrote:
>
>> I am using threads in my
>> foreign data wrapper and i get the following error when i use the threads .
>>
>> *ERROR: stack depth limit exceeded*
>> *HINT: Increase the configuration parameter "max_stack_depth" (currently
>> 2048kB), after ensuring the platform's stack depth limit is adequate.*

> PostgreSQL is a process-per-backend model.

To elaborate on that, it is a process per backend and most of the code
in that process has not been written for safe execution by multiple
threads. If your code starts other threads that only do other things,
but only one ever touches PostgreSQL backend code, that can be ok.
This happens in PL/Java, but it uses several interrelated precautions
to make sure no thread ever enters PostgreSQL backend code unless every
other thread is known to be out.

Even if you are taking that precaution, if the backend code is entered
by a different thread than last executed there, the stack depth tests
may be made by comparing the last thread's stack base to the current
thread's stack pointer, which will naturally give you a bogus result.
There is some API in miscadmin.h for manipulating the backend's idea
of the stack base, but there be dragons.

I am far short of the knowledgeable voices here, but in case you don't
hear from them right away, that is at least how I understand the matter.

Chapman Flack

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Konstantin Knizhnik 2015-12-21 07:48:52 Re: Threads in PostgreSQL
Previous Message Pavel Stehule 2015-12-21 06:44:14 Re: Unique index problem

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2015-12-21 07:26:25 Re: Re: BUG #13685: Archiving while idle every archive_timeout with wal_level hot_standby
Previous Message Michael Paquier 2015-12-21 06:35:58 Re: Tab completion for ALTER COLUMN SET STATISTICS