reverted: --- b/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ a/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -84,10 +84,7 @@ public function read($name) { $data = FALSE; try { + $raw = $this->connection->query('SELECT [data] FROM {' . $this->connection->escapeTable($this->table) . '} WHERE [collection] = :collection AND [name] = :name', [':collection' => $this->collection, ':name' => $name], $this->options)->fetchField(); - $raw = $this->connection->query('SELECT [data] FROM {' . $this->connection->escapeTable($this->table) . '} WHERE [collection] = :collection AND [name] = :name ORDER BY collection, name', [ - ':collection' => $this->collection, - ':name' => $name, - ], $this->options)->fetchField(); if ($raw !== FALSE) { $data = $this->decode($raw); } diff -u b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php --- b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -352,7 +352,7 @@ } /** - * Retrieves a sequence name that is owned by the table and column. + * Retrieves a sequence name that is owned by the table and column.. * * @param string $table * A table name that is not prefixed or quoted. @@ -386,7 +386,6 @@ public function sequenceExists($name) { $args = [':name' => $name]; return (bool) $this -// ->query("SELECT c.relname FROM pg_class as c INNER JOIN pg_namespace as ns ON (c.relnamespace = ns.oid) WHERE c.relkind = 'S' AND c.relname = :name", $args) ->query("SELECT c.relname FROM pg_class as c WHERE c.relkind = 'S' AND c.relname = :name", $args) ->fetchField(); } diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1567,8 +1567,6 @@ // likely serial columns. $entity_types = \Drupal::entityTypeManager()->getDefinitions(); // @var \Drupal\Core\Entity\EntityTypeInterface $entity_type - $sandbox['max'] = count($sandbox['tables']); - $sandbox['progress'] = 0; foreach ($entity_types as $entity_type) { $storage_class = $entity_type->getStorageClass(); if (is_subclass_of($storage_class, SqlContentEntityStorage::class)) { @@ -1595,10 +1593,14 @@ } } + + $sandbox['max'] = count($sandbox['tables']); + $sandbox['progress'] = 0; + } else { // Adds ownership of orphan sequences to tables. - $to_process = array_slice($sandbox['tables'], $sandbox['progress'], 50); + $to_process = array_splice($sandbox['tables'], $sandbox['progress'], 50); // Ensures that a sequence is not owned first, then ensures that the a // sequence exists at all before trying to alter it. diff -u b/core/modules/system/tests/fixtures/update/drupal-8.pgsql-orphan-sequence.php b/core/modules/system/tests/fixtures/update/drupal-8.pgsql-orphan-sequence.php --- b/core/modules/system/tests/fixtures/update/drupal-8.pgsql-orphan-sequence.php +++ b/core/modules/system/tests/fixtures/update/drupal-8.pgsql-orphan-sequence.php @@ -4,7 +4,6 @@ use Drupal\Core\Database\Database; $connection = Database::getConnection(); - $db_type = $connection->databaseType(); if ($db_type === 'pgsql') { diff -u b/core/modules/system/tests/modules/pgsql_test/pgsql_test.info.yml b/core/modules/system/tests/modules/pgsql_test/pgsql_test.info.yml --- b/core/modules/system/tests/modules/pgsql_test/pgsql_test.info.yml +++ b/core/modules/system/tests/modules/pgsql_test/pgsql_test.info.yml @@ -6 +6 @@ - +core: 8.x only in patch2: unchanged: --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -958,7 +958,7 @@ EOD; // not when altering. Because of that, the sequence needs to be created // and initialized by hand. $seq = $this->connection->makeSequenceName($table, $field_new); - $this->connection->query("CREATE SEQUENCE " . $seq); + $this->connection->query("CREATE SEQUENCE " . $seq . " OWNED BY {" . $table . "}." . $field_new); // Set sequence to maximal field value to not conflict with existing // entries. $this->connection->query("SELECT setval('" . $seq . "', MAX(\"" . $field . '")) FROM {' . $table . "}"); @@ -1016,6 +1016,25 @@ EOD; } } + /** + * Alters the ownership of a sequence. + * + * This is used for updating orphaned sequences. + * See issue https://www.drupal.org/project/drupal/issues/3028706 + * + * @param string $table + * The unquoted or prefixed table name. + * @param string $column + * The column name for the sequence. + * + * @internal + */ + public function updateSequenceOwnership($table, $column) { + $seq = $this->connection->makeSequenceName($table, $column); + $table_name = $this->connection->prefixTables('{' . $table . '}'); + $this->connection->query('ALTER SEQUENCE IF EXISTS ' . $seq . ' OWNED BY ' . $table_name . '.' . $column); + } + /** * Retrieve a table or column comment. */