pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Grigory Smolkin <g.smolkin@postgrespro.ru>
To: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: logical replication: could not create file "state.tmp": File exists
Date: Sat, 30 Nov 2019 15:09:39 +0300
Message-ID: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru> (raw)

Hello!

One of my colleagues encountered an out of space condition, which broke 
his logical replication setup.
It`s manifested with the following errors:

ERROR:  could not receive data from WAL stream: ERROR:  could not create 
file "pg_replslot/some_sub/state.tmp": File exists

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.

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.

-- 
Grigory Smolkin
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

  replication_bug.sh (application/x-shellscript, 1.4K) download

0001-logical_replication_fix.patch (text/x-patch, 542B) download diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 21ae8531b3..ef415b44c8 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1253,7 +1253,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel) sprintf(tmppath, "%s/state.tmp", dir); sprintf(path, "%s/state", dir); - fd = OpenTransientFile(tmppath, O_CREAT | O_EXCL | O_WRONLY | PG_BINARY); + fd = OpenTransientFile(tmppath, O_CREAT | O_TRUNC | O_WRONLY | PG_BINARY); if (fd < 0) { ereport(elevel,

view thread (11+ messages)  latest in thread

Message-ID: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru>
Permalink:  ../08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru/
Also on:    postgresql.org/message-id/08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru

 ·  · 

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: g.smolkin@postgrespro.ru
  Subject: Re: logical replication: could not create file "state.tmp": File exists
  In-Reply-To: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru>
  References: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru>

* 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