pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedpg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum
3+ messages / 2 participants
[nested] [flat]
* pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum
@ 2022-02-17 21:09 Daniel Shelepanov <deniel1495@mail.ru>
2022-02-18 16:56 ` Re: pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shelepanov @ 2022-02-17 21:09 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
Hello everyone!
I've been examining a floating bug in pg_visibility. To reproduce it,
you have to:
1) apply a patch to pg_visibility's tests (you can find it attached)
2) run test-icx.sh (attached) from the root of the postgresql's source tree
pg_vis_clean.patch adds one additional test to pg_visibility test suite
and normally it is expected to pass. However, when (I assume so) it
happens to run in parallel with autovacuum, the test is failed.
test-icx.sh runs several parallel installchecks on contrib/pg_visibility
tests and there is a chance that some of them will catch this error.
This is the set-up for a bug reproduction:
*create table vacuum_test as select 42 i;**
**vacuum (disable_page_skipping) vacuum_test;**
*
This is the actual test result:
*diff -U3
/tmp/icx/ic01-1/contrib/pg_visibility/expected/pg_visibility.out
/tmp/icx/ic01-1/contrib/pg_visibility/results/pg_visibility.out**
**--- /tmp/icx/ic01-1/contrib/pg_visibility/expected/pg_visibility.out
2022-02-17 23:46:26.005500630 +0300**
**+++ /tmp/icx/ic01-1/contrib/pg_visibility/results/pg_visibility.out
2022-02-17 23:47:36.066838872 +0300**
**@@ -247,7 +247,7 @@**
** select count(*) > 0 from pg_check_visible('vacuum_test');**
** ?column?**
** ----------**
**- f**
**+ t**
** (1 row)**
**
** -- cleanup*
The thing is that the underlying file is one page long which should
contain the only all-visible tuple and pg_check_visible should return
nothing. Is this a real bug or do I miss something? Thank you in advance
for the response
P. S.: SELECT version(); result: *PostgreSQL 14.2 on
x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04)
9.3.0, 64-bit*
Attachments:
test-icx.sh (application/x-shellscript, 15.9K) download
pg_vis_clean.patch (text/x-patch, 1.5K) download
diff --git a/contrib/pg_visibility/expected/pg_visibility.out b/contrib/pg_visibility/expected/pg_visibility.out
index 315633bfea6..0a15133246a 100644
--- a/contrib/pg_visibility/expected/pg_visibility.out
+++ b/contrib/pg_visibility/expected/pg_visibility.out
@@ -242,6 +242,14 @@ select * from pg_check_frozen('copyfreeze');
--------
(0 rows)
+create table vacuum_test as select 42 i;
+vacuum (disable_page_skipping) vacuum_test;
+select count(*) > 0 from pg_check_visible('vacuum_test');
+ ?column?
+----------
+ f
+(1 row)
+
-- cleanup
drop table test_partitioned;
drop view test_view;
@@ -252,3 +260,4 @@ drop foreign data wrapper dummy;
drop materialized view matview_visibility_test;
drop table regular_table;
drop table copyfreeze;
+drop table vacuum_test;
diff --git a/contrib/pg_visibility/sql/pg_visibility.sql b/contrib/pg_visibility/sql/pg_visibility.sql
index ff3538f9964..e644818239d 100644
--- a/contrib/pg_visibility/sql/pg_visibility.sql
+++ b/contrib/pg_visibility/sql/pg_visibility.sql
@@ -170,6 +170,10 @@ commit;
select * from pg_visibility_map('copyfreeze');
select * from pg_check_frozen('copyfreeze');
+create table vacuum_test as select 42 i;
+vacuum (disable_page_skipping) vacuum_test;
+select count(*) > 0 from pg_check_visible('vacuum_test');
+
-- cleanup
drop table test_partitioned;
drop view test_view;
@@ -180,3 +184,4 @@ drop foreign data wrapper dummy;
drop materialized view matview_visibility_test;
drop table regular_table;
drop table copyfreeze;
+drop table vacuum_test;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum
2022-02-17 21:09 pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum Daniel Shelepanov <deniel1495@mail.ru>
@ 2022-02-18 16:56 ` Andres Freund <andres@anarazel.de>
2022-02-18 17:51 ` Re: pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 3+ messages in thread
From: Andres Freund @ 2022-02-18 16:56 UTC (permalink / raw)
To: Daniel Shelepanov <deniel1495@mail.ru>; +Cc: pgsql-bugs@lists.postgresql.org
Hi,
On 2022-02-18 00:09:48 +0300, Daniel Shelepanov wrote:
> I've been examining a floating bug in pg_visibility. To reproduce it, you
> have to:
>
> 1) apply a patch to pg_visibility's tests (you can find it attached)
>
> 2) run test-icx.sh (attached) from the root of the postgresql's source tree
Could you try to minimize the script? A 300 line reproducer is quite long. And
it looks like it won't even work in non postgres-pro tree.
One thing to do would be to modify pg_visibility to elog(PANIC, "something")
when it encounters corruption. Then you would have a chance of inspecting the
state of the tuple/page in that moment.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum
2022-02-17 21:09 pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum Daniel Shelepanov <deniel1495@mail.ru>
2022-02-18 16:56 ` Re: pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum Andres Freund <andres@anarazel.de>
@ 2022-02-18 17:51 ` Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 3+ messages in thread
From: Andres Freund @ 2022-02-18 17:51 UTC (permalink / raw)
To: Daniel Shelepanov <deniel1495@mail.ru>; Robert Haas <robertmhaas@gmail.com>; Amit Kapila <amit.kapila16@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org
Hi,
On 2022-02-18 08:56:37 -0800, Andres Freund wrote:
> Could you try to minimize the script? A 300 line reproducer is quite long. And
> it looks like it won't even work in non postgres-pro tree.
>
> One thing to do would be to modify pg_visibility to elog(PANIC, "something")
> when it encounters corruption. Then you would have a chance of inspecting the
> state of the tuple/page in that moment.
Oh, I have been able to reliably reproduce this on HEAD. I modified
record_corrupt_item() to PANIC and then:
psql regression:
BEGIN ;SELECT txid_current();
<leave open>
psql postgres
DROP TABLE IF EXISTS vacuum_test_0;
create table vacuum_test_0 as select 42 i;
vacuum (disable_page_skipping) vacuum_test_0;
select * from pg_check_visible('vacuum_test_0');
At which point there immediately is a crash.
This reproduces in earlier versions too, at least back to 10.
I *think* this is a false positive:
- PGPROC->xmin is computed without regard for the database in which the other
sessions are running. Due to the the txid_current() session this includes an
older xid.
- During the VACUUM in vis.sql the only connection to the database pgbench
connects to is VACUUM and thus ignored when determining horizons (due to
PROC_IN_VACUUM). Therefore the horizon is computed to latestCompletedXid +
1.
- But during pg_check_visible(), the current session is *not* marked as
PROC_IN_VACUUM. So the horizon is the xid from the txid_current().
Boom.
Greetings,
Andres Freund
Attachments:
repro.sql (application/sql, 720B) download
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2022-02-18 17:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17 21:09 pg_visibility's pg_check_visible() yields false positive when working in parallel with autovacuum Daniel Shelepanov <deniel1495@mail.ru>
2022-02-18 16:56 ` Andres Freund <andres@anarazel.de>
2022-02-18 17:51 ` Andres Freund <andres@anarazel.de>
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