Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XuOT6-0003ga-T5 for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Nov 2014 16:32:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XuOT6-0003RB-8Q for pgsql-bugs@arkaria.postgresql.org; Fri, 28 Nov 2014 16:32:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XuOT5-0003Qu-2k for pgsql-bugs@postgresql.org; Fri, 28 Nov 2014 16:32:27 +0000 Received: from srv01.sipibox.fr ([195.154.178.222]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XuOSx-0001v8-Bb for pgsql-bugs@postgresql.org; Fri, 28 Nov 2014 16:32:25 +0000 Received: from [192.168.251.101] (unknown [78.193.54.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by srv01.sipibox.fr (Postfix) with ESMTPSA id C235026C00E2 for ; Fri, 28 Nov 2014 17:32:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sipibox.fr; s=42; t=1417192333; bh=DNKVCywHJCktn6zK5OxMjDpRpJp8Nwm2wXin5W4oP8Q=; h=Date:From:To:Subject:From; b=Nd7ZpVKt1xIDR7q+TIpDwtymybB/7sPu/zknGFy7reUEodsD6poBzqZB2uJ+RShW4 emBOCPtSiexWAw+FO9SxWae0xy0AjTMuAYzGn+/iPWZY7l9jZJhdiVMpOXOnDDGxTb DzMs9aJhh3KdgHg2hAhHWwSByjutqrBm+galhBlg= Message-ID: <5478A390.3030705@sipibox.fr> Date: Fri, 28 Nov 2014 17:32:16 +0100 From: =?UTF-8?B?RnJhbsOnb2lzIEJhdHRhaWw=?= Organization: SIPiBOX User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: PQfinish() in a C multi-threaded application Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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