postgresql への接続には libpqxx を使用しています。そして、1行の1つのテーブルでserialazableクエリを実行するまで、すべて問題ありませんでした。
テーブル:
CREATE TABLE t1(id integer primary key);
ポストグル 9.4.4_x64
pqxx::connection c1(conn_str);
pqxx::connection c2(conn_str);
pqxx::transaction<pqxx::isolation_level::serializable> t1(c1);
t1.exec("INSERT INTO t1 (id) VALUES (25)");
pqxx::transaction<pqxx::isolation_level::serializable> t2(c2);
t2.exec("INSERT INTO t1 (id) VALUES (25)"); //hang here
t2.commit();
t1.commit();
私のプログラムは永久にハングします。PQexec 関数でハングします。なんで?トランザクションの1つをロールバックする必要があると思いますか? でもいいえ?ハングアップするだけです。
更新:純粋な libpq の場合と同じ結果:
c1 = PQconnectdb(conninfo);
c2 = PQconnectdb(conninfo);
res1 = PQexec(c1, "BEGIN");
PQclear(res1);
res1 = PQexec(c1, "INSERT INTO t1 (id) VALUES (104)");
PQclear(res1);
res2 = PQexec(c2, "BEGIN");
PQclear(res2);
res2 = PQexec(c2, "INSERT INTO t1 (id) VALUES (104)");
PQclear(res2);
res2 = PQexec(c2, "END");
PQclear(res2);
res1 = PQexec(c1, "END");
PQclear(res1);
postgresql 9.1 - 同じハング