emqx5社区版使用postgresql授权的时候无法连接

环境信息

  • EMQX 版本:5 社区版
  • 操作系统及版本:CentOS7.8
  • 其他

问题描述

emqx5社区版使用postgresql授权的时候无法连接,总是提示“已断开”。几乎相同的配置(除了sql查询语句不一样)在认证可以正常工作
sql语句:

select 'allow'  as permission  ,'all' as action  ,topic 
from sbms_mqtt_acl sbms_mqtt_acl 
where username = ${useranme}

配置文件及日志

2022-07-27T00:05:28.101608+08:00 [error] Supervisor: {<0.4105.0>,ecpool_worker_sup}. Context: start_error. Reason: {error,error,<<"42601">>,syntax_error,<<232,175,173,230,179,149,233,148,153,232,175,175,32,229,156,168,32,34,36,34,32,230,136,150,233,153,132,232,191,145,231,154,132>>,[{file,<<"scan.l">>},{line,<<"1180">>},{position,<<"93">>},{routine,<<"scanner_yyerror">>},{severity,<<233,148,153,232,175,175>>}]}. Offender: id={worker,1},pid=undefined.

2022-07-27T00:05:28.102092+08:00 [error] Supervisor: {<0.4103.0>,ecpool_pool_sup}. Context: start_error. Reason: {shutdown,{failed_to_start_child,{worker,1},{error,error,<<"42601">>,syntax_error,<<232,175,173,230,179,149,233,148,153,232,175,175,32,229,156,168,32,34,36,34,32,230,136,150,233,153,132,232,191,145,231,154,132>>,[{file,<<"scan.l">>},{line,<<"1180">>},{position,<<"93">>},{routine,<<"scanner_yyerror">>},{severity,<<233,148,153,232,175,175>>}]}}}. Offender: id=worker_sup,pid=undefined.

2022-07-27T00:05:28.103222+08:00 [error] line: 45, mfa: emqx_plugin_libs_pool:start_pool/3, msg: start_ecpool_error, pool_name: 'emqx_connector_pgsql:5:38', reason: {{shutdown,{failed_to_start_child,worker_sup,{shutdown,{failed_to_start_child,{worker,1},{error,error,<<"42601">>,syntax_error,<<232,175,173,230,179,149,233,148,153,232,175,175,32,229,156,168,32,34,36,34,32,230,136,150,233,153,132,232,191,145,231,154,132>>,[{file,<<"scan.l">>},{line,<<"1180">>},{position,<<"93">>},{routine,<<"scanner_yyerror">>},{severity,<<233,148,153,232,175,175>>}]}}}}},{child,undefined,{pool_sup,'emqx_connector_pgsql:5:38'},{ecpool_pool_sup,start_link,['emqx_connector_pgsql:5:38',emqx_connector_pgsql,[{host,{127,0,0,1}},{port,5432},{username,<<"testdb">>},{password,<<"password">>},{database,<<"testdb5">>},{auto_reconnect,15},{pool_size,4},{prepare_statement,[{<<"emqx_connector_pgsql:5">>,<<"select 'allow'  as permission  ,'all' as action  ,topic from sbms_mqtt_acl where username = ${useranme}">>}]},{ssl,false}]]},transient,false,infinity,supervisor,[ecpool_pool_sup]}}

2022-07-27T00:05:28.102240+08:00 [error] crasher: initial call: ecpool_worker:init/1, pid: <0.4106.0>, registered_name: [], exit: {{error,error,<<"42601">>,syntax_error,<<232,175,173,230,179,149,233,148,153,232,175,175,32,229,156,168,32,34,36,34,32,230,136,150,233,153,132,232,191,145,231,154,132>>,[{file,<<"scan.l">>},{line,<<"1180">>},{position,<<"93">>},{routine,<<"scanner_yyerror">>},{severity,<<233,148,153,232,175,175>>}]},[{gen_server,init_it,6,[{file,"gen_server.erl"},{line,407}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}, ancestors: [<0.4105.0>,<0.4103.0>,ecpool_sup,<0.2513.0>], message_queue_len: 0, messages: [], links: [<0.4105.0>,<0.4107.0>], dictionary: [], trap_exit: true, status: running, heap_size: 610, stack_size: 28, reductions: 409; neighbours: neighbour: pid: <0.4107.0>, registered_name: [], initial call: epgsql_sock:init/1, current_function: {gen_server,loop,7}, ancestors: [<0.4106.0>,<0.4105.0>,<0.4103.0>,ecpool_sup,<0.2513.0>], message_queue_len: 0, links: [<0.4106.0>,#Port<0.128>], trap_exit: false, status: waiting, heap_size: 2586, stack_size: 12, reductions: 66494, current_stacktrace: [{gen_server,loop,7,[{file,"gen_server.erl"},{line,443}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]

2022-07-27T00:05:28.104099+08:00 [warning] line: 405, message: <<"resource down: emqx_connector_pgsql:5">>, mfa: emqx_alarm:do_actions/3, msg: alarm_is_activated, name: <<"emqx_connector_pgsql:5">>


可能是pgsql的prepare过程失败,看下你的sql语句直接在pgsql里执行有没有问题。
PS:你的pgsql的版本是?