aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Riggs <simon@2ndQuadrant.com>2011-07-04 09:30:50 +0100
committerSimon Riggs <simon@2ndQuadrant.com>2011-07-04 09:30:50 +0100
commit1f7056099728035b55efcd8f889c7b705a68b6de (patch)
tree06a49894cf74d489a22e429c02769252967b382f
parent3569e02c98d2802e6fc4912a3ba67dc25e76b6cc (diff)
downloadpostgresql-1f7056099728035b55efcd8f889c7b705a68b6de.tar.gz
postgresql-1f7056099728035b55efcd8f889c7b705a68b6de.zip
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.
-rw-r--r--doc/src/sgml/release-9.1.sgml17
-rw-r--r--src/backend/commands/tablecmds.c28
2 files changed, 29 insertions, 16 deletions
diff --git a/doc/src/sgml/release-9.1.sgml b/doc/src/sgml/release-9.1.sgml
index 9dfca1c7866..914464eb6c3 100644
--- a/doc/src/sgml/release-9.1.sgml
+++ b/doc/src/sgml/release-9.1.sgml
@@ -846,8 +846,7 @@
<listitem>
<para>
- Add functions to control streaming replication replay (Simon
- Riggs)
+ Add functions to control streaming replication replay (Simon Riggs)
</para>
<para>
@@ -1742,20 +1741,6 @@
</para>
</listitem>
- <listitem>
- <para>
- Minimize lock levels for <link
- linkend="SQL-CREATETRIGGER"><command>CREATE TRIGGER</></link>
- and many <link linkend="SQL-ALTERTABLE"><command>ALTER
- TABLE</></link> and <link linkend="SQL-CREATERULE"><command>CREATE
- RULE</></link> operations (Simon Riggs)
- </para>
-
- <para>
- This improves database availability when altering active databases.
- </para>
- </listitem>
-
</itemizedlist>
</sect4>
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index fcfe1faeb45..029d33a223d 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -2573,6 +2573,31 @@ AlterTableInternal(Oid relid, List *cmds, bool recurse)
LOCKMODE
AlterTableGetLockLevel(List *cmds)
{
+ /*
+ * Late in 9.1 dev cycle a number of issues were uncovered with access
+ * to catalog relations, leading to the decision to re-enforce all DDL
+ * at AccessExclusiveLock level by default.
+ *
+ * The issues are that there is a pervasive assumption in the code that
+ * the catalogs will not be read unless an AccessExclusiveLock is held.
+ * If that rule is relaxed, we must protect against a number of potential
+ * effects - infrequent, but proven possible with test cases where
+ * multiple DDL operations occur in a stream against frequently accessed
+ * tables.
+ *
+ * 1. Catalog tables are read using SnapshotNow, which has a race bug
+ * that allows a scan to return no valid rows even when one is present
+ * in the case of a commit of a concurrent update of the catalog table.
+ * SnapshotNow also ignores transactions in progress, so takes the
+ * latest committed version without waiting for the latest changes.
+ *
+ * 2. Relcache needs to be internally consistent, so unless we lock the
+ * definition during reads we have no way to guarantee that.
+ *
+ * 3. Catcache access isn't coordinated at all so refreshes can occur at
+ * any time.
+ */
+#ifdef REDUCED_ALTER_TABLE_LOCK_LEVELS
ListCell *lcmd;
LOCKMODE lockmode = ShareUpdateExclusiveLock;
@@ -2721,6 +2746,9 @@ AlterTableGetLockLevel(List *cmds)
if (cmd_lockmode > lockmode)
lockmode = cmd_lockmode;
}
+#else
+ LOCKMODE lockmode = AccessExclusiveLock;
+#endif
return lockmode;
}