Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2t4x-0000Uq-6o for pgsql-general@arkaria.postgresql.org; Wed, 28 Aug 2019 08:13:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i2t4v-0007Ql-Mt for pgsql-general@arkaria.postgresql.org; Wed, 28 Aug 2019 08:13:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i2t4v-0007Qe-A5 for pgsql-general@lists.postgresql.org; Wed, 28 Aug 2019 08:13:17 +0000 Received: from serveurmail01.codata.be ([82.146.123.190]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1i2t4s-0006GM-Da for pgsql-general@lists.postgresql.org; Wed, 28 Aug 2019 08:13:16 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by serveurmail01.codata.be (Postfix) with ESMTP id 83D96900E7; Wed, 28 Aug 2019 10:13:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at serveurmail01.codata.be Received: from serveurmail01.codata.be ([127.0.0.1]) by localhost (serveurmail01.codata.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rgK9IZJODO5W; Wed, 28 Aug 2019 10:13:10 +0200 (CEST) Received: from [10.0.0.100] (38-179-112-217.fix.adsl.belcenter.be [217.112.179.38]) by serveurmail01.codata.be (Postfix) with ESMTPSA id 24480900DA; Wed, 28 Aug 2019 10:13:10 +0200 (CEST) Reply-To: arnaud.listes@codata.eu Subject: Re: psql \copy hanging To: Luca Ferrari Cc: pgsql-general References: <6947a518-82dd-fc26-57b3-6da5e8b89445@codata.eu> <4f450814-5697-06b1-651b-540cac0a10b0@codata.eu> <574a09e0-cf01-4664-c61c-c2d0ae9300f9@codata.eu> <89fb69a6-ff8e-9182-4557-e4a3a8ac3905@codata.eu> From: "Arnaud L." Message-ID: <8dbfafa9-cf8c-c2b5-2bca-846e0d564c68@codata.eu> Date: Wed, 28 Aug 2019 10:13:09 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Le 28/08/2019 à 09:43, Luca Ferrari a écrit : > I don't want to be pedantic, but I would have tried with a single > change at a time. > And my bet is: the local file would do the trick (i.e., it is a weird > share problem). You're not don't worry. This process is quite important in our workflow (not critical), so I can't really afford to make tests for weeks. Moving the offending line to the end of the script is what I'd consider "single change". To me it makes something clear : the problem occurs only at the very specific time this command is running. > If you are going to invest some time, you could also try to write a > small file on the share just before the copy starts, so that you are > guaranteed the share is working. Something like: > > echo $(date) >> $SHARE/log.txt > psql 'copy ...' > echo 'done' >> $SHARE/log.txt Well, I do know that the share is working just before this command runs because ALL the commands in the script write to this specific share. The script is basically outputting many views results in a single share, something like : \copy (select * from view1) TO '\\myserver\myshare\file1.csv' \copy (select * from view2) TO '\\myserver\myshare\file2.csv' ... \copy (select * from view99) TO '\\myserver\myshare\file99.csv' So the \copy command right before (say view15 for instance) is writing to this same share just milliseconds before the the problematic command (view16) tries to do the same. Since this particular view takes some time to execute, there is some time between the moment the file gets created on the share (which happens immediately when the \copy command runs if I get it right), and the moment psql receives content and starts writing to it (my tests suggest 1min to 1min30s). Either psql doesn't receive anything (possible, since the connection is marked as active but it does not look as if it's doing anything at all), or there has been some timeout. It could have been tcp keepalive, but in Windows the default is 2h I believe and postgresql uses system default if nothing is specified in conf (which is my case). So with all this in mind I'd rather think I have a problem with either psql's \copy or with my query on the server side. But I'm not rulling anything out of course. One other thing I could try is using COPY TO STDOUT \g. From what I understand in the documentation this would not be 100% similar to what \copy is doing. Anyway, if it works with the current setup I won't dig into it much deeper. Cheers -- Arnaud