@@ -1473,6 +1473,127 @@ select * from another;
1473
1473
1474
1474
drop table another;
1475
1475
--
1476
+ -- lock levels
1477
+ --
1478
+ drop type lockmodes;
1479
+ ERROR: type "lockmodes" does not exist
1480
+ create type lockmodes as enum (
1481
+ 'AccessShareLock'
1482
+ ,'RowShareLock'
1483
+ ,'RowExclusiveLock'
1484
+ ,'ShareUpdateExclusiveLock'
1485
+ ,'ShareLock'
1486
+ ,'ShareRowExclusiveLock'
1487
+ ,'ExclusiveLock'
1488
+ ,'AccessExclusiveLock'
1489
+ );
1490
+ drop view my_locks;
1491
+ ERROR: view "my_locks" does not exist
1492
+ create or replace view my_locks as
1493
+ select case when c.relname like 'pg_toast%' then 'pg_toast' else c.relname end, max(mode::lockmodes) as max_lockmode
1494
+ from pg_locks l join pg_class c on l.relation = c.oid
1495
+ where virtualtransaction = (
1496
+ select virtualtransaction
1497
+ from pg_locks
1498
+ where transactionid = txid_current()::integer)
1499
+ and locktype = 'relation'
1500
+ and relnamespace != (select oid from pg_namespace where nspname = 'pg_catalog')
1501
+ and c.relname != 'my_locks'
1502
+ group by c.relname;
1503
+ create table alterlock (f1 int primary key, f2 text);
1504
+ NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "alterlock_pkey" for table "alterlock"
1505
+ -- share update exclusive
1506
+ begin; alter table alterlock alter column f2 set statistics 150;
1507
+ select * from my_locks order by 1;
1508
+ relname | max_lockmode
1509
+ -----------+--------------------------
1510
+ alterlock | ShareUpdateExclusiveLock
1511
+ (1 row)
1512
+
1513
+ rollback;
1514
+ begin; alter table alterlock cluster on alterlock_pkey;
1515
+ select * from my_locks order by 1;
1516
+ relname | max_lockmode
1517
+ ----------------+--------------------------
1518
+ alterlock | ShareUpdateExclusiveLock
1519
+ alterlock_pkey | ShareUpdateExclusiveLock
1520
+ (2 rows)
1521
+
1522
+ commit;
1523
+ begin; alter table alterlock set without cluster;
1524
+ select * from my_locks order by 1;
1525
+ relname | max_lockmode
1526
+ -----------+--------------------------
1527
+ alterlock | ShareUpdateExclusiveLock
1528
+ (1 row)
1529
+
1530
+ commit;
1531
+ begin; alter table alterlock set (fillfactor = 100);
1532
+ select * from my_locks order by 1;
1533
+ relname | max_lockmode
1534
+ -----------+--------------------------
1535
+ alterlock | ShareUpdateExclusiveLock
1536
+ pg_toast | ShareUpdateExclusiveLock
1537
+ (2 rows)
1538
+
1539
+ commit;
1540
+ begin; alter table alterlock reset (fillfactor);
1541
+ select * from my_locks order by 1;
1542
+ relname | max_lockmode
1543
+ -----------+--------------------------
1544
+ alterlock | ShareUpdateExclusiveLock
1545
+ pg_toast | ShareUpdateExclusiveLock
1546
+ (2 rows)
1547
+
1548
+ commit;
1549
+ begin; alter table alterlock set (toast.autovacuum_enabled = off);
1550
+ select * from my_locks order by 1;
1551
+ relname | max_lockmode
1552
+ -----------+--------------------------
1553
+ alterlock | ShareUpdateExclusiveLock
1554
+ pg_toast | ShareUpdateExclusiveLock
1555
+ (2 rows)
1556
+
1557
+ commit;
1558
+ begin; alter table alterlock set (autovacuum_enabled = off);
1559
+ select * from my_locks order by 1;
1560
+ relname | max_lockmode
1561
+ -----------+--------------------------
1562
+ alterlock | ShareUpdateExclusiveLock
1563
+ pg_toast | ShareUpdateExclusiveLock
1564
+ (2 rows)
1565
+
1566
+ commit;
1567
+ begin; alter table alterlock alter column f2 set (n_distinct = 1);
1568
+ select * from my_locks order by 1;
1569
+ relname | max_lockmode
1570
+ -----------+--------------------------
1571
+ alterlock | ShareUpdateExclusiveLock
1572
+ (1 row)
1573
+
1574
+ rollback;
1575
+ begin; alter table alterlock alter column f2 set storage extended;
1576
+ select * from my_locks order by 1;
1577
+ relname | max_lockmode
1578
+ -----------+--------------------------
1579
+ alterlock | ShareUpdateExclusiveLock
1580
+ (1 row)
1581
+
1582
+ rollback;
1583
+ -- share row exclusive
1584
+ begin; alter table alterlock alter column f2 set default 'x';
1585
+ select * from my_locks order by 1;
1586
+ relname | max_lockmode
1587
+ -----------+-----------------------
1588
+ alterlock | ShareRowExclusiveLock
1589
+ (1 row)
1590
+
1591
+ rollback;
1592
+ -- cleanup
1593
+ drop table alterlock;
1594
+ drop view my_locks;
1595
+ drop type lockmodes;
1596
+ --
1476
1597
-- alter function
1477
1598
--
1478
1599
create function test_strict(text) returns text as
0 commit comments