Is is safe to use SPI in multiple threads?

From: Qiu Xiafei <qiuxiafei(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Is is safe to use SPI in multiple threads?
Date: 2016-12-09 08:52:05
Message-ID: CA+ag+4PGWbnHQx35Hswmd0aeMg8LkH5HTwApPtEwuGv=EJKUXA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, buddies!

I'm new to PG and want to implement my domain-specific system based on PG.
I wish to arrange my data as several tables in database and translate my
DSL into SQL statements for query. Since one DSL statement may be mapped to
several SQL statements, it's better to push the DSL server as close to the
PG server as possible. I found PG's backgroud worker meet my needs. I can
setup a background worker bounded to PG server and listen to a port for
network requests.

But I encounter a problem that the Server Programing Interfaces are not
THREAD SAFE. There are some global variables defined like: SPI_processed,
SPI_tuptable, etc. This limit to my DSL server to work in single thread
mode which is quite inefficient. So my questions are:

1. Is there a way to use SPI in multi-thread style?
2. Another option is to use libpq, like normal clients do. Is libpq as
efficient as SPI?

Thanks in advance!

Xiafei Qiu

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Johann Spies 2016-12-09 08:55:12 Re: After upgrade to 9.6: waiting column does not exist
Previous Message Thomas.Deboben.ext 2016-12-09 08:43:55 Windows installation - could not connect to server: Connection refused (0x0000274D/10061)