PostgresqlエラーERROR、0A000、「キャッシュされたプランは結果タイプを変更してはなりません」



Postgresql Error Error



os:ubuntu 16.04
db:postgresql 9.6.8

postgresqlログファイルには次のエラーメッセージがあります。



'BIND',ERROR,0A000,'cached plan must not change result type',,,,,,'select c0,c1 from ''public''.tmp_t0 WHERE ( c0 = $1 )',,,''

無関係な情報を省略し、sqlもアナログ置換を行いました。

ログを確認したところ、テーブルの変更列の変更操作があり、再実行時に準備が使用されていたことがわかりました。



デモの下で
セッション1

postgres=# create table tmp_t0(c0 varchar(10)) CREATE TABLE postgres=# insert into tmp_t0(c0)select '1' INSERT 0 1 postgres=# select * from tmp_t0 c0 ---- 1 (1 row) postgres=# deallocate prepare select_tmp_t0_plan ERROR: prepared statement 'select_tmp_t0_plan' does not exist postgres=# postgres=# prepare select_tmp_t0_plan as select * from tmp_t0 where c0=$1 PREPARE postgres=# postgres=# select * from pg_prepared_statements name | statement | prepare_time | parameter_types | from_sql --------------------+-----------------------------------------------------------------+------------------------------+-----------------+---------- select_tmp_t0_plan | prepare select_tmp_t0_plan as select * from tmp_t0 where c0=$1 | 2019-04-18 15:26:27.90271+08 | {text} | t (1 row) postgres=# execute select_tmp_t0_plan('1') c0 ---- 1 (1 row) postgres=#

セッション2

postgres=# alter table public.tmp_t0 alter column c0 type varchar(100) ALTER TABLE

セッション1



postgres=# execute select_tmp_t0_plan('1') ERROR: cached plan must not change result type

これは確かに事実です!

解決

  1. すべて破棄する 再プレ後
  2. pgjdbcドライバーを autosave = conservative

参照:
https://github.com/pgjdbc/pgjdbc/issues/496
https://github.com/pgjdbc/pgjdbc/pull/451
https://stackoverflow.com/questions/2783813/postgres-error-cached-plan-must-not-change-result-type
http://stackoverflow.com/questions/34180932/error-cached-plan-must-not-change-result-type-when-mixing-ddl-with-select-via

https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters

https://segmentfault.com/a/1190000012444511

https://jdbc.postgresql.org/documentation/head/connect.html#connection-parameters
https://github.com/digoal/blog/blob/master/201904/20190417_01.md