admin管理员组

文章数量:1658727

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 也做了模拟替换.

查看日志后发现是前面有进行 alter table alter column 操作,从而引发了再次执行时使用了 prepare .

演示下
session 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=#  

session 2

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

session 1

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

确实是这样啊!

解决办法

  1. discard all 后,重新 prepare
  2. configuring your pgjdbc driver with autosave=conservative

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

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

https://segmentfault/a/1190000012444511

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

本文标签: 报错quotpostgresqlErrorresult