pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: François Battail <francois.battail@sipibox.fr>
To: pgsql-bugs@postgresql.org
Subject: PQfinish() in a C multi-threaded application
Date: Fri, 28 Nov 2014 17:32:16 +0100
Message-ID: <5478A390.3030705@sipibox.fr> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Dear List,

I've a (large) multi-threaded application in C using PostgreSQL 9.3 on 
Ubuntu 14.04 LTS x86_64 and it /seems/ that when a thread close a 
connection using PQfinish() all pgsql connections *program wide* are 
closed, here's an overview of this application:

main thread:

connect db
create tables
create worker threads (1 up to 20 workers)
wait for threads termination
analyze
index
close db

worker thread:

connect db
prepare statements
start transaction
mass insert (10.10^6 records)
end transaction
close db

All database connections are strictly isolated in local storage (auto) 
variables.

When the main thread is trying to execute the SQL analyze statement, 
after worker threads have completed, PQexec() fails and PQerrorMessage() 
returns:

Creating tables...
Done.
Inserting...
Done.
Analyzing tables (be patient)...
Analyze failed, error: 1 (connection pointer is NULL)

If I don't call PQfinish() in the worker threads, the application just 
runs completely fine and data are created as designed (checked with psql).

Am I missing something? I've seen so far nothing about such a behaviour 
both in documentation and in Web searches (including this mailing list).

BTW forgive my bad English (I'm French ;-) )

Best regards


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)  latest in thread

Message-ID: <5478A390.3030705@sipibox.fr>
Permalink:  ../5478A390.3030705@sipibox.fr/
Also on:    postgresql.org/message-id/5478A390.3030705@sipibox.fr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: francois.battail@sipibox.fr
  Subject: Re: PQfinish() in a C multi-threaded application
  In-Reply-To: <5478A390.3030705@sipibox.fr>
  References: <5478A390.3030705@sipibox.fr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox