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 1ibko0-0003EX-Mv for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Dec 2019 12:27:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ibknx-0003qy-MH for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Dec 2019 12:27:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ibknx-0003qr-BZ for pgsql-bugs@lists.postgresql.org; Mon, 02 Dec 2019 12:27:53 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ibknu-00006b-8K for pgsql-bugs@lists.postgresql.org; Mon, 02 Dec 2019 12:27:52 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id B596C21C3FBC for ; Mon, 2 Dec 2019 15:27:48 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.174] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 6DA2521C3F98 for ; Mon, 2 Dec 2019 15:27:48 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1575289668; bh=jVxfeFjqw5zdD8xku01WJKHtC19CntrJIzrPqXhhIJ0=; h=Subject:To:References:From:Date:In-Reply-To; b=a7JewRcDypiiMzRjfJ/prfSNh6YmYq2ISgWzClhkmMtI0vbyIyjVL2Cut8AWmZSgf 9oTZF0nG411ztoX0LSJmIyBSlhv4TPkMUIyf7c1LSw0KHCXqYSh6Jf0pIV8Rc8sd3j Yt4gkIPNHVTw5QLqeJNhCBy9HzYirCyOuE6z1CBw= Subject: Re: logical replication: could not create file "state.tmp": File exists To: pgsql-bugs@lists.postgresql.org References: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru> <20191202043547.GE1696@paquier.xyz> From: Grigory Smolkin Message-ID: <6ea8cf93-ca74-ceb0-18bc-4fc5f8f55df1@postgrespro.ru> Date: Mon, 2 Dec 2019 15:27:48 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20191202043547.GE1696@paquier.xyz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/2/19 7:35 AM, Michael Paquier wrote: > On Sat, Nov 30, 2019 at 03:09:39PM +0300, Grigory Smolkin wrote: >> I`ve digged a bit into this problem, and it`s turned out that in >> SaveSlotToPath() temp file for replication slot is opened with 'O_CREAT | >> O_EXCL' flags, which makes this routine as not very reentrant. > What did you see as I/O problem before facing the actual error > reported here? Was it just ENOSPC, a fsync failure, or just a failure > in closing the fd? The first pattern is mostly what I guess happened, > still a fsync failure would not trigger a PANIC here (actually we > really should do that!), but I am raising a different thread about > that issue. Hello! I didn`t see the very first error that left behind the temp file. I`ve requested it just now, but it will take some time to get it (there are several terabytes of text log). But I assume that it was out of space error, which, by the look of the code, should produce ERROR and leave temp file behind, just as it happened in aforementioned  case. > >> Since an exclusive lock is taken before temp file creation, I think it >> should be safe to replace O_EXCL with O_TRUNC. >> Script to reproduce and patch are attached. > Agreed. I prefer the O_TRUNC option because that's less code churn. > Also, as it can still be useful to have a look at the temporary state > file after a crash or a failure, doing unlink() in the error code > paths is no good option IMO. I`m sorry, but it was an production system, so, as I understand it, stale temp file was hastily deleted without long considerations. Thank you for your interest in this topic. > > Have others thoughts or objections to share? > -- > Michael -- Grigory Smolkin Postgres Professional: http://www.postgrespro.com The Russian Postgres Company