Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2c3d9db

Browse files
Reset ALTER TABLE lock levels to AccessExclusiveLock in all cases.
Locks on inheritance parent remain at lower level, as they were before. Remove entry from 9.1 release notes.
1 parent 4fa046a commit 2c3d9db

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

doc/src/sgml/release-9.1.sgml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,7 @@
846846

847847
<listitem>
848848
<para>
849-
Add functions to control streaming replication replay (Simon
850-
Riggs)
849+
Add functions to control streaming replication replay (Simon Riggs)
851850
</para>
852851

853852
<para>
@@ -1742,20 +1741,6 @@
17421741
</para>
17431742
</listitem>
17441743

1745-
<listitem>
1746-
<para>
1747-
Minimize lock levels for <link
1748-
linkend="SQL-CREATETRIGGER"><command>CREATE TRIGGER</></link>
1749-
and many <link linkend="SQL-ALTERTABLE"><command>ALTER
1750-
TABLE</></link> and <link linkend="SQL-CREATERULE"><command>CREATE
1751-
RULE</></link> operations (Simon Riggs)
1752-
</para>
1753-
1754-
<para>
1755-
This improves database availability when altering active databases.
1756-
</para>
1757-
</listitem>
1758-
17591744
</itemizedlist>
17601745

17611746
</sect4>

src/backend/commands/tablecmds.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,31 @@ AlterTableInternal(Oid relid, List *cmds, bool recurse)
25782578
LOCKMODE
25792579
AlterTableGetLockLevel(List *cmds)
25802580
{
2581+
/*
2582+
* Late in 9.1 dev cycle a number of issues were uncovered with access
2583+
* to catalog relations, leading to the decision to re-enforce all DDL
2584+
* at AccessExclusiveLock level by default.
2585+
*
2586+
* The issues are that there is a pervasive assumption in the code that
2587+
* the catalogs will not be read unless an AccessExclusiveLock is held.
2588+
* If that rule is relaxed, we must protect against a number of potential
2589+
* effects - infrequent, but proven possible with test cases where
2590+
* multiple DDL operations occur in a stream against frequently accessed
2591+
* tables.
2592+
*
2593+
* 1. Catalog tables are read using SnapshotNow, which has a race bug
2594+
* that allows a scan to return no valid rows even when one is present
2595+
* in the case of a commit of a concurrent update of the catalog table.
2596+
* SnapshotNow also ignores transactions in progress, so takes the
2597+
* latest committed version without waiting for the latest changes.
2598+
*
2599+
* 2. Relcache needs to be internally consistent, so unless we lock the
2600+
* definition during reads we have no way to guarantee that.
2601+
*
2602+
* 3. Catcache access isn't coordinated at all so refreshes can occur at
2603+
* any time.
2604+
*/
2605+
#ifdef REDUCED_ALTER_TABLE_LOCK_LEVELS
25812606
ListCell *lcmd;
25822607
LOCKMODE lockmode = ShareUpdateExclusiveLock;
25832608

@@ -2726,6 +2751,9 @@ AlterTableGetLockLevel(List *cmds)
27262751
if (cmd_lockmode > lockmode)
27272752
lockmode = cmd_lockmode;
27282753
}
2754+
#else
2755+
LOCKMODE lockmode = AccessExclusiveLock;
2756+
#endif
27292757

27302758
return lockmode;
27312759
}

0 commit comments

Comments
 (0)