Low Traffic Mail Server - DBD::mysql::st execute failed: MySQL server has gone away

Discussion in 'Tips/Tricks/Mods' started by sjau, Apr 4, 2024.

  1. sjau

    sjau Local Meanie Moderator

    One of my ISPConfig installations in a low traffic mail server - arround 100 to 150 emails per day. Looking at the mail.log I noticed regularly entries like this:

    Code:
    Mar 31 06:05:04 ispc amavis[1654713]: (1654713-07) NOTICE: reconnecting in response to: err=2006, HY000, DBD::mysql::st execute failed: MySQL server has gone away at (eval 99) line 173, <GEN32> line 26805.
    
    However despite reconnecting, mariadb got stuck and I had sometimes to restart the service. My first solution was add a cron that did just restart mariadb every now and then.

    The reason for this error is that amavis - mariadb connection will time out at a given point if no new emails arrive. A simple fix for this is to edit the /etc/amavis/conf.d/50-user file. Go right to the end and insert above the last two lines the max_servers and max_requests entries like this:

    Code:
    $max_servers = 1;
    $max_requests = 1;
    #------------ Do not modify anything below this line -------------
    1;  # insure a defined return
    
    You also need to adjust the amavis server settings in /etc/postfix/master.cf:
    Change
    Code:
    amavis unix - - - - 2 smtp
    
    to
    Code:
    amavis unix - - - - 1 smtp
    
    Then restart amavis and postfix
    Code:
    systemctl restart amavis
    systemctl restart postfix
    
    This has fixed the problem for me.
     
    Last edited: Apr 6, 2024
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Is that really true? Seems strange feature.
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    This is indeed the case, but as far as I know, it's MySQL that disconnects Amavis due to the inactivity of the database connection. Amavis will reconnect automatically, it detects that it got disconnected and will just create a new connection, so this is not a failure. The above log line just informs that this happened.
     
  4. sjau

    sjau Local Meanie Moderator

    Unfortunately regularly it does not reconnect again and restart of MariaDB is required.
     
  5. Hostking

    Hostking New Member

    You could reconfigure the /etc/my.cnf file with higher values like max_allowed_packet
    I used to notice before throughout the years that that particular error was related to that value though I could be wrong.
     

Share This Page