Re: Issue with logical replication: MyPgXact->xmin already is valid

From: Petr Jelinek <petr(dot)jelinek(at)2ndquadrant(dot)com>
To: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Subject: Re: Issue with logical replication: MyPgXact->xmin already is valid
Date: 2017-10-07 13:26:21
Message-ID: 8d1f0a4d-42fc-7207-96d1-e6cfa8340550@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 06/10/17 16:46, Konstantin Knizhnik wrote:
>
>
> On 06.10.2017 15:29, Petr Jelinek wrote:
>> On 06/10/17 12:16, Konstantin Knizhnik wrote:
>>> When creating logical replication slots we quite often get the following
>>> error:
>>>
>>> ERROR:  cannot build an initial slot snapshot when MyPgXact->xmin
>>> already is valid
>>>
>>> which cause restart of WAL sender.
>>> The comment to this line doesn't clarify much:
>>>
>>>      /* so we don't overwrite the existing value */
>>>      if (TransactionIdIsValid(MyPgXact->xmin))
>>>          elog(ERROR, "cannot build an initial slot snapshot when
>>> MyPgXact->xmin already is valid");
>>> I wonder if it is normal situation or something goes wrong?
>>>
>> Hi,
>>
>> no it's not normal situation, it seems you are doing something that
>> assigns xid before you run the CREATE_REPLICATION_SLOT command on that
>> connection.
>
> I have not doing something in this connection: it is wal sender
> executing CREATE_REPLICATION_SLOT replication command.
> Please look at the stack in my original e-mail. It shows who and when is
> setting MyPgXact->xmin.
> It is GetSnapshotData called because of reloading configuration settings.
> And configuration setting are reloaded because our application is
> updating "synchronous_standby_names".
>
>

Hmm so you start transaction (you have to when running
CREATE_REPLICATION_SLOT with USE_SNAPSHOT parameter). And while the slot
is being created the config is reloaded. And since now you are in
transaction the tsearch hook for GUC processing tries to access catalogs
which sets the xmin for the transaction.

That's not good, but I can't really say I have idea about what to do
with it other than to set some kind of flag saying that logical decoding
snapshot is being built and using that to skip catalog access which does
not seem very pretty.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2017-10-07 13:34:47 Re: On markers of changed data
Previous Message Petr Jelinek 2017-10-07 13:21:44 Re: Discussion on missing optimizations