2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
4 # Test CREATE INDEX CONCURRENTLY with concurrent modifications
6 use warnings FATAL
=> 'all';
8 use PostgreSQL
::Test
::Cluster
;
9 use PostgreSQL
::Test
::Utils
;
18 $node = PostgreSQL
::Test
::Cluster
->new('CIC_test');
20 $node->append_conf('postgresql.conf',
21 'lock_timeout = ' . (1000 * $PostgreSQL::Test
::Utils
::timeout_default
));
23 $node->safe_psql('postgres', q
(CREATE EXTENSION amcheck
));
24 $node->safe_psql('postgres', q
(CREATE TABLE tbl
(i
int)));
25 $node->safe_psql('postgres', q
(CREATE INDEX idx ON tbl
(i
)));
28 # Stress CIC with pgbench.
30 # pgbench might try to launch more than one instance of the CIC
31 # transaction concurrently. That would deadlock, so use an advisory
32 # lock to ensure only one CIC runs at a time.
35 '--no-vacuum --client=5 --transactions=100',
37 [qr{actually processed}],
39 'concurrent INSERTs and CIC',
41 '002_pgbench_concurrent_transaction' => q
(
43 INSERT INTO tbl VALUES
(0);
46 '002_pgbench_concurrent_transaction_savepoints' => q
(
49 INSERT INTO tbl VALUES
(0);
52 '002_pgbench_concurrent_cic' => q
(
53 SELECT pg_try_advisory_lock
(42)::integer AS gotlock \gset
55 DROP INDEX CONCURRENTLY idx
;
56 CREATE INDEX CONCURRENTLY idx ON tbl
(i
);
57 SELECT bt_index_check
('idx',true
);
58 SELECT pg_advisory_unlock
(42);