Intermittent CDR connection failures

Running Asterisk 22.4.1 with FreePBX 17 on Oracle Linux 9.6 with MariaDB 12.

I am getting intermittent errors in Asterisk console:

Unable to retrieve database handle.  CDR failed.

MariaDB is on the same server, so it can’t be a network issue. Had it been a configuration error, there should have been no CDR records at all. As it is, this is an intermittent issue with some records getting lost.

/etc/odbc.ini:

[MySQL-asteriskcdrdb]
Description = MySQL connection to ‘asteriskcdrdb’ database
Driver = MySQL
Server = localhost
Database = asteriskcdrdb
Port = 3306
Socket = /var/lib/mysql/mysql.sock
Option = 3
username = asterisk
password = PASSWORD

/etc/asterisk/res_odbc_additional.conf:

[asteriskcdrdb]
enabled=>yes
dsn=>MySQL-asteriskcdrdb
pre-connect=>yes
max_connections=>5
username=>freepbxuser
password=>94dbeec506815118a5aa05e9d883b1b9
database=>asteriskcdrdb

/etc/asterisk/cdr_odbc.conf:

[global]
dsn=MySQL-asteriskcdrdb
username=freepbxuser
password=94dbeec506815118a5aa05e9d883b1b9
loguniqueid=yes
dispositionstring=yes
table=cdr ;“cdr” is default table name
usegmtime=no ; set to “yes” to log in GMT
hrtime=yes ;Enables microsecond accuracy with the billsec and duration fields
newcdrcolumns=yes ; Enable logging of post-1.8 CDR columns (peeraccount, linkedid, sequence)

/etc/asterisk/cdr_adaptive_odbc.conf:

[asteriskcdrdb]
connection=asteriskcdrdb
loguniqueid=1
table=cdr
alias start => calldate

cdr show status:

Call Detail Record (CDR) settings

Logging: Enabled
Mode: Simple
Log calls by default: Yes
Log unanswered calls: No
Log congestion: No
Ignore bridging changes: No
Ignore dial state changes: No

  • Registered Backends

    ODBC
    cdr_manager
    csv
    Adaptive ODBC

ODBC DSN Settings

Name: asteriskcdrdb
DSN: MySQL-asteriskcdrdb
Number of active connections: 2 (out of 5)
Logging: Disabled

Is the database connection timing out due to lack of activity e.g. at night when nobody is on the phone ? Or are these intermittent errors occurring during the middle of peak usage times ?

You might consider looking into MySQL/MariaDB’s wait_timeout setting: Server System Variables | MariaDB Documentation

It’s daytime now and I am seeing the error. Hardly any activity at the moment. Just one call came in and was answered by the operator.

CPU utilization is hardly 2%, RAM mostly free.

CDR table has about 20 records for today.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.