[pgpool-general-jp: 1306] INSERTされたデータのシーケンス値がずれる
TED CBP Narita Takayoshi
narita.tk @ teldevice.co.jp
2014年 10月 17日 (金) 17:54:23 JST
お世話になります。成田と申します。
pgpool-II をレプリケーションモードで利用させていただいております。
さて、'ERROR: duplicate key value violates...'に陥るようなSQLを同時実行したときに
INSERTされたデータのシーケンス値がずれる動作を確認しました。
「環境」
pgpool-II: 3.1.12
PostgreSQL: 9.2.4
OS: CentOS 5.8
pgpool-IIの配下に2つのPostgreSQLバックエンドを置いてレプリケーションで利用(参考 pgpool.conf)
「再現方法」
スクリプト動作概要説明:
1. 'ERROR: duplicate key value violates...'に陥るようなSQLを同時実行
2. バックエンドの片側
から、対象テーブル(reptest)のシーケンス値を取得し、標準出力からDB内のテーブル(reptest_seqs)に書き出す
3. reptest_seqsの値をwhere句に指定してreptestを更新するupdate文をpgpool-II経由で実行するとpgpoolが不整合を検出
準備: seq_consistency.tar.gz を解凍後、seq_consistency 内に移動し、dbconfig の内容を環境に合わせて編集する。
実行: ./check_seq_value.bash
出力例:
DROP TABLE
psql:setupreptest.sql:2: NOTICE: CREATE TABLE will create implicit sequence "reptest_id_seq" for serial column "reptest.id"
psql:setupreptest.sql:2: NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "reptest_pkey" for table "reptest"
CREATE TABLE
DROP TABLE
CREATE TABLE
INSERT 0 1
psql:reptest.sql:1: ERROR: duplicate key value violates unique constraint "reptest_pkey"
DETAIL: Key (b)=(1) already exists.
INSERT 0 1
psql:reptest.sql:1: ERROR: duplicate key value violates unique constraint "reptest_pkey"
DETAIL: Key (b)=(1) already exists.
psql:reptest.sql:2: ERROR: duplicate key value violates unique constraint "reptest_pkey"
DETAIL: Key (b)=(2) already exists.
psql:reptest.sql:2: ERROR: duplicate key value violates unique constraint "reptest_pkey"
DETAIL: Key (b)=(2) already exists.
psql:reptest.sql:1: ERROR: duplicate key value violates unique constraint "reptest_pkey"
DETAIL: Key (b)=(1) already exists.
INSERT 0 1
INSERT 0 1
INSERT 0 1
psql:reptest.sql:3: ERROR: duplicate key value violates unique constraint "reptest_pkey"
DETAIL: Key (b)=(3) already exists.
psql:reptest.sql:1: ERROR: duplicate key value violates unique constraint "reptest_pkey"
:
:
done.
ERROR: pgpool detected difference of the number of inserted, updated or deleted tuples. Possible last query was: "update reptest set c=id where id in (select id from reptest_seqs);"
HINT: check data consistency between master and other db node
「確認したい点」
動作の報告のみで恐縮ですが、この動作の原因について何か考えられる点は有りますでしょうか。
不足情報、スクリプト動作不備など有りましたらお知らせください。
#バージョン3.2,3.3ではまだ試しておりません。試したら報告致します。
以上、よろしくお願い申し上げます。
-------------- next part --------------
テキスト形式以外の添付ファイルを保管しました...
ファイル名: seq_consistency.tar.gz
型: application/x-gzip
サイズ: 848 バイト
説明: seq_consistency.tar.gz
URL: <http://www.sraoss.jp/pipermail/pgpool-general-jp/attachments/20141017/d4f0fa69/attachment-0001.gz>
-------------- next part --------------
テキスト形式以外の添付ファイルを保管しました...
ファイル名: pgpool.conf
型: application/octet-stream
サイズ: 19653 バイト
説明: pgpool.conf
URL: <http://www.sraoss.jp/pipermail/pgpool-general-jp/attachments/20141017/d4f0fa69/attachment-0001.obj>
pgpool-general-jp メーリングリストの案内