Postgres insert queries that fail in a transaction break the entire transaction

Created on 12 May 2015, over 9 years ago
Updated 31 August 2023, over 1 year ago

Problem/Motivation

Once a query fails as part of a transaction Postgres (unlike Mysql, SQLite and Oracle) will prevent further queries from using the transaction. See https://stackoverflow.com/questions/10399727/psqlexception-current-trans... for more information about how postgres behaves. Allowing inserts to fail within a transaction is especially important because of the way we automatically create cache bins on demand - see \Drupal\Core\Cache\DatabaseBackend for how this works.

Proposed resolution

Add a savepoint to the postgres insert query - this is already done for other query types, for example, updates and selects.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Original issue summary

PDO randomly throws errors for any table (mostly seen for queue and flood during normal site operation) when using PGBouncer in transaction mode on PostgreSQL:
PDOException: SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: currval of sequence "queue_item_id_seq" is not yet defined in this session: INSERT INTO queue (name, data, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2);

When doing lots of inserts (e.g. setting up a new site) it will break the installation.

πŸ› Bug report
Status

Fixed

Version

8.0 ⚰️

Component
PostgreSQL driverΒ  β†’

Last updated 10 days ago

No maintainer
Created by

πŸ‡©πŸ‡ͺGermany Oliver Sommersberg

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024