Gradual CPU usage increase with ODBC on Asterisk 20.16.0

Hi everyone,

I’m running Asterisk 20.16.0 and facing a CPU usage issue after switching from shell-based database access to ODBC.

Until recently, my dialplan interacted with a MariaDB database using Bash scripts called via System() and ${SHELL()}. This setup worked reliably for a long time. Recently, I migrated to ODBC, using res_odbc and func_odbc, as well as cdr_adaptive_odbc and made minor changes to the dialplan to use these functions directly.

Since this change, Asterisk starts the day with normal CPU usage (servers reboot daily at 6 AM), but CPU load slowly increases throughout the day and never drops. Within about 14 hours, Asterisk consumes all CPU resources, forcing a restart.

I’d appreciate guidance on how to diagnose or resolve this issue. Please let me know what additional information or logs would be useful, and I’ll share them.

Below are my current configurations for res_odbc.conf, odbc.ini, cdr_adaptive_odbc.conf and func_odbc.conf.

res_odbc.conf

[DBLOCAL]
enabled => yes
dsn => dblocal
username => alex
password => XXXXXXXXXXXX
pre-connect => yes
sanitysql => select 1
max_connections => 10
connect_timeout => 5
negative_connection_cache => 300

[DBREMOTO]
enabled => yes
dsn => dbremoto
username => alex
password => XXXXXXXXXXXXX
pre-connect => yes
sanitysql => select 1
max_connections => 10
connect_timeout => 5
negative_connection_cache => 300

func_odb.conf


[general]
single_db_connection=no

[SQL]
prefix = LOCAL
writehandle=DBLOCAL
readsql=${ARG1}

[SQL]
prefix = REMOTO
writehandle=DBREMOTO
readsql=${ARG1}

[CALL]
prefix=CONF
dsn=DBLOCAL
readsql=SELECT parametro,valor FROM confserv WHERE serv='${ARG1}'
mode=multirow

cdr_adaptive_odbc.conf


[con1]
connection=DBLOCAL
table=cdr

odbc.ini:


[dblocal]
Description = Banco local
Driver = MariaDB Unicode
SERVER = localhost
Socket = /var/run/mysqld/mysqld.sock
DATABASE = provoice
UID = alex
PASSWORD = XXXXXXXXXXXX

[dbremoto]
Description = Banco remoto
Driver = MariaDB Unicode
SERVER = pv2.pvtelecom.com.br
PORT = 3306
DATABASE = provoice
UID = alex
PASSWORD = XXXXXXXXXXXXXXX