"unexpected duplicate for tablespace" problem in logical replication
wangsh.fnst@fujitsu.com <wangsh.fnst@fujitsu.com>
From: "wangsh.fnst@fujitsu.com" <wangsh.fnst@fujitsu.com>
To: "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2022-04-06T02:14:26Z
Lists: pgsql-bugs
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Ignore temporary relations in RelidByRelfilenumber()
- 30b32b08c9e9 13.23 landed
- 222130edd81f 14.20 landed
- ec471008c8fc 15.15 landed
- ab874faaa1f3 16.11 landed
- dcdc95cb4d4c 17.7 landed
- 86831952ad60 18.0 landed
- ef03ea01fe47 19 (unreleased) landed
Attachments
- run.sh (application/x-shellscript)
- 0001-Check-the-duplicated-relfilenode-when-create-table-o.patch (text/x-patch) patch 0001
Hi, I met a problem while using logical replication in PG11 and I think all the PG version have this problem. The log looks like: > ERROR: unexpected duplicate for tablespace 0, relfilenode xxxxxxx Someone also reported this problem in [1], but no one has responded to it. I did some investigation, and found a way to reproduce this problem. The steps are: 1. create a table (call it tableX) and truncate it. 2. cycle through 2^32 OIDs. 3. restart the database to clear all the cache. 4. create a temp table which make the temp table's OID equals to the tableX's relfilenode and insert any data into tableX. The attachment(run.sh) can reproduce this problem in PG10 and PG11with the help of option 'WITH OIDS'. I don't find any way to cycle the OIDs quickly in branch master, but I use the gdb to reproduce this problem too. Now, function GetNewRelFileNode() only checks: 1. duplicated OIDs in pg_class. 2. relpath(rnode) is exists in disk. However, the result of relpath(temp table) and relpath(non-temp table) are different, temp table's relpath() has a prefix "t%d". That means, if there is a table that value of relfilenode is 20000(but the value of oid isn't 20000), it's possible to create a temp table that value of relfilenode is also 20000. I think function GetNewRelFileNode() should always check the duplicated relfilenode, see the patch(a simple to way to fix this problem is master branch). Any comment? Regards, Shenhao Wang [1] https://www.postgresql.org/message-id/flat/CAM5YvKTPxmMT%3DS7iPcu5SgmaOv4S4nhE1HZRO_sdFX9cXeXXOQ%40mail.gmail.com