Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nClCe-0006vf-Dt for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 16:31:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nClCc-0001IT-It for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 16:31:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nClCc-0001HO-2m for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 16:31:22 +0000 Received: from mail-qt1-x833.google.com ([2607:f8b0:4864:20::833]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nClCY-0002n7-RE for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 16:31:20 +0000 Received: by mail-qt1-x833.google.com with SMTP id y17so123972qtx.9 for ; Wed, 26 Jan 2022 08:31:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:to:content-language:from :subject; bh=LPeF1JNs29jvVogITdqW48CZheX7rAlZIWzB+B3G1Jc=; b=Zp+KYGkxveleHhebWIRPiMHl38hB4S7nM3DJL5Px68BH+Kcwk7LA++5wtZqtPcoGu2 9q8CtscwK2hyRSCMpRf8EHrZwOFVJ9P4z1oJ6KmJB7PEZ5VBBBcntXcMI6xl8Z2SLbb4 ErcK6vYDqrW4PNW+NTodO56XnA5ErKZkcTKgfDg5l8LIqPhH7X3jFW7NSGTQhnP01wk7 t6R/rJ87hpmZEDaPARibKKyAmGRqUj2GUWhbi0ZKxJJXfU8YSz+uBc90YmW+wCC/yf9E 5+C981WvEPwD9YocashglbxklBhTPk2KsSHrbVnBP9se42egnc/T/Au/mxSAZuf4VDTZ riQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:to :content-language:from:subject; bh=LPeF1JNs29jvVogITdqW48CZheX7rAlZIWzB+B3G1Jc=; b=f322HUIkcmJY5NAZcntDdeG57ZEg3o9RHVdRU06QLzZeLPdgIgUm4tfcaj0uzNvg+m D3RnDpGvnYOoBof2laPlYzRuPyGPiZ+N6zPOixVYAApE61LOINYQaI1WT54A9tdm4kPI VKtfR3PQC5Dwb7DgySNsmCFlEBS4vHLxZOzqi1UsdmLaZLzaGLPX5idI3RQ+Jj2zCGjw vAjXXa5O7+Tyx4v9UqHiwFf6Y+/nxH7J5c1rPSIxQRkEo5e8G14Q+XWHgzAGlPwDWOsq X+ASvpzYl9OCU3+EIrqO7d4Gdh9HJR0bjcB+3T9fPhLcrkyrqhJ+TbLQtd4ie/yE0e5X MJLA== X-Gm-Message-State: AOAM531e7fkhkJIThtao/fmbqgWSoiIgLJ0FyZmctVznPzpe2Ts/MiZx j+ScWWUpdHjYAnarnCvRtNk6AZQhFuSU8A== X-Google-Smtp-Source: ABdhPJxslKTqXtnBaC/uooMLSflywY9HMysOdZWuSmbu24fSGdnMvvM5MJ5cAIZBX5s1I5nXSMwmVA== X-Received: by 2002:ac8:4e4b:: with SMTP id e11mr10022334qtw.122.1643214676394; Wed, 26 Jan 2022 08:31:16 -0800 (PST) Received: from [192.168.2.100] (pool-72-79-19-93.nwrknj.east.verizon.net. [72.79.19.93]) by smtp.gmail.com with ESMTPSA id 22sm1029869qtw.95.2022.01.26.08.31.15 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jan 2022 08:31:15 -0800 (PST) Content-Type: multipart/alternative; boundary="------------h8DPqnW0r5ct2HdjxQFKPyD0" Message-ID: Date: Wed, 26 Jan 2022 11:31:14 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 To: pgsql-general Content-Language: en-US From: Mladen Gogala Subject: Could not serialize access due to concurrent update List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------h8DPqnW0r5ct2HdjxQFKPyD0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit In this post, I am not asking a question, I am sharing an experience. The application is running on Linux, PostgreSQL 13.5. using Websphere 9 application server. When using "SKIP LOCKED" option, I suddenly started seeing errors like "Could not serialize access due to concurrent update". After some reading, the problem was pinpointed to the transaction isolation level: https://pganalyze.com/docs/log-insights/app-errors/U138 OK, the app is not setting transaction isolation level to repeatable read, so what's going on? The documentation for Websphere reveals the truth: https://www.ibm.com/support/pages/transaction-isolation-levels-and-websphere-application-server *If you do not specify the isolation level* The product does not require you to set the isolation level on a data source resource reference for a non-CMP application module. If you do not specify isolation level on the resource reference, or if you specify TRANSACTION_NONE, the WebSphere Application Server run time uses a default isolation level for the data source. Application Server uses a default setting based on the JDBC driver. *For most drivers, WebSphere Application Server uses an isolation level default of TRANSACTION_REPEATABLE_READ. *(Bold font is my addition) Fortunately, the same document explains how to set the transaction isolation level to READ COMMITTED for the Websphere data source. No wonder that IBM stands for "It's Better Manually". Be vewy, vewy cawefull when using Websphere and PostgreSQL. Here is how to deal with the problem: *Possible values* *JDBC isolation level* *DB2 isolation level* 8 TRANSACTION_SERIALIZABLE Repeatable Read (RR) 4 (default) TRANSACTION_REPEATABLE_READ Read Stability (RS) 2 TRANSACTION_READ_COMMITTED Cursor Stability (CS) 1 TRANSACTION_READ_UNCOMMITTED Uncommitted Read (UR) 0 TRANSACTION_NONE No Commit (NC) *Note**:* If TRANSACTION_NONE is used, the DB file does not have to be journaled. To define this custom property for a data source, you should do the following: 1. Click *Resources* > *JDBC provider* > */JDBC_provider/*. 2. Click *Data sources* in the Additional Properties section. 3. Click the name of the data source. 4. Click *Custom properties*. 5. Create the webSphereDefaultIsolationLevel custom property a. Click *New*. b. Enter *webSphereDefaultIsolationLevel* for the name field. c. Enter one of the *"possible values*" in the value field from the table above.**i.e. 0, 1, 2, 4, or 8 The value that needs to be entered is 2. ** * * -- Mladen Gogala Database Consultant Tel: (347) 321-1217 https://dbwhisperer.wordpress.com --------------h8DPqnW0r5ct2HdjxQFKPyD0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

In this post, I am not asking a question, I am sharing an experience. The application is running on Linux, PostgreSQL 13.5.  using Websphere 9 application server. When using "SKIP LOCKED" option, I suddenly started seeing errors like "Could not serialize access due to concurrent update". After some reading, the problem was pinpointed to the transaction isolation level:

https://pganalyze.com/docs/log-insights/app-errors/U138

OK, the app is not setting transaction isolation level to repeatable read, so what's going on? The documentation for Websphere reveals the truth:

https://www.ibm.com/support/pages/transaction-isolation-levels-and-websphere-application-server

If you do not specify the isolation level

The product does not require you to set the isolation level on a data source resource reference for a non-CMP application module. If you do not specify isolation level on the resource reference, or if you specify TRANSACTION_NONE, the WebSphere Application Server run time uses a default isolation level for the data source. Application Server uses a default setting based on the JDBC driver.

For most drivers, WebSphere Application Server uses an isolation level default of TRANSACTION_REPEATABLE_READ.  (Bold font is my addition)

Fortunately, the same document explains how to set the transaction isolation level to READ COMMITTED for the Websphere data source. No wonder that IBM stands for "It's Better Manually". Be vewy, vewy cawefull when using Websphere and PostgreSQL. Here is how to deal with the problem:


Possible values JDBC isolation level DB2 isolation level
8 TRANSACTION_SERIALIZABLE Repeatable Read (RR)
4 (default) TRANSACTION_REPEATABLE_READ Read Stability (RS)
2 TRANSACTION_READ_COMMITTED Cursor Stability (CS)
1 TRANSACTION_READ_UNCOMMITTED Uncommitted Read (UR)
0 TRANSACTION_NONE No Commit (NC)


Note: If TRANSACTION_NONE is used, the DB file does not have to be journaled.

To define this custom property for a data source, you should do the following:
1. Click Resources > JDBC provider > JDBC_provider.
2. Click Data sources in the Additional Properties section.
3. Click the name of the data source.
4. Click Custom properties.
5. Create the webSphereDefaultIsolationLevel custom property
a. Click New.
b. Enter webSphereDefaultIsolationLevel for the name field.
c. Enter one of the "possible values" in the value field from the table above. i.e. 0, 1, 2, 4, or 8

The value that needs to be entered is 2.


-- 
Mladen Gogala
Database Consultant
Tel: (347) 321-1217
https://dbwhisperer.wordpress.com
--------------h8DPqnW0r5ct2HdjxQFKPyD0--