From: Andres Freund <andres@anarazel.de>
To: Grigory Smolkin <g.smolkin@postgrespro.ru>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: logical replication: could not create file "state.tmp": File exists
Date: Mon, 2 Dec 2019 08:12:22 -0800
Message-ID: <20191202161222.sazl2omhhk5pl3nl@alap3.anarazel.de> (raw)
In-Reply-To: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru>
References: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru>
Hi,
On 2019-11-30 15:09:39 +0300, Grigory Smolkin wrote:
> 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
Hm. What was the log output leading to this state? Some cases of this
would end up in a PANIC, which'd remove the .tmp file during
recovery. But there's some where we won't - it seems the right fix for
this would be to unlink the tmp file in that case?
> 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.
I'm very doubtful about this. I think it's a good safety measure to
ensure that there's no previous state file that we're somehow
overwriting.
> Script to reproduce and patch are attached.
Well:
> # Imitate out_of_space/write_operation_error
> touch ${PGDATA_PUB}/pg_replslot/mysub/state.tmp
Doesn't really replicate how we got into this state...
Greetings,
Andres Freund
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: andres@anarazel.de, g.smolkin@postgrespro.ru
Subject: Re: logical replication: could not create file "state.tmp": File exists
In-Reply-To: <20191202161222.sazl2omhhk5pl3nl@alap3.anarazel.de>
References: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru> <20191202161222.sazl2omhhk5pl3nl@alap3.anarazel.de>
* 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