Re: Is is safe to use SPI in multiple threads?

From: Qiu Xiafei <qiuxiafei(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Is is safe to use SPI in multiple threads?
Date: 2016-12-11 05:39:35
Message-ID: CA+ag+4PMreaDHehteaVPG0NEXKBzuRrF=xar+EBYO8NLg7u6JA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks for your reply.

Because of the one-backend-per-session concept of PG, I think I should bind
one my DSL session to one bg worker only. It seems work. But is there a way
to launch a bg worker when a new session starts, just like pg's
per-session-backend do? Is it possible to run a bg worker for incoming
sessions and to launch a new bg worker to handle the session when it comes?

On Saturday, December 10, 2016, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
wrote:

> On Fri, Dec 09, 2016 at 02:37:58PM -0800, Andres Freund wrote:
> > On 2016-12-09 16:52:05 +0800, Qiu Xiafei wrote:
> > > 1. Is there a way to use SPI in multi-thread style?
> >
> > No.
> >
> > > 2. Another option is to use libpq, like normal clients do. Is libpq as
> > > efficient as SPI?
> >
> > No.
>
> To give more details here, Postgres relies heavily on the fact that
> sessions
> working in parallel on the backend should be done in separate processes,
> like for transaction or snapshot handling.
> --
> Michael
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Paquier 2016-12-11 06:50:56 Re: Is is safe to use SPI in multiple threads?
Previous Message Igor Korot 2016-12-11 05:09:39 Re: Importing SQLite database