Agentur ist umgezogen ✨mehr info

Plesk Emails Stuck in Queue – Fix “Can’t connect to local MySQL server through socket (13)

3. Mai 2026
2 min Lesezeit

Problem

If emails are not being sent in Plesk and remain in the mail queue, you may see errors like:

421 4.3.2 Service shutting down
relay=127.0.0.1[127.0.0.1]:10024

and in the mail log:

connect_to_sql: unable to connect to DSN 'DBI:MariaDB:database=emailsecurity...'
Can't connect to local server through socket '/var/lib/mysql/mysql.sock' (13)

This indicates that the mail filtering component (Amavis) cannot access the database required for processing emails.

Background

Plesk uses a multi-step mail delivery chain:

Postfix → Amavis (port 10024) → MariaDB (emailsecurity database)

Postfix hands emails to Amavis for spam and virus checks. Amavis requires access to the emailsecurity database. If that connection fails, the message is rejected internally and remains in the queue.

Solution 1 (Official Plesk Fix)

Plesk provides an official fix related to SELinux contexts:
https://support.plesk.com/hc/en-us/articles/12387612284695-Mail-stuck-in-the-queue-in-the-server-with-Plesk-Can-t-connect-to-local-MySQL-server-through-socket-var-lib-mysql-mysql-sock-13

Apply:

restorecon -Rv /var/lib/mysql
restorecon -v /var/lib/mysql/mysql.sock
systemctl restart mariadb
systemctl restart amavisd
postqueue -f

This resets file security contexts and restarts the services. In many cases, this resolves the issue.

When This Does Not Work

On newer systems (for example MariaDB 11 combined with SELinux), the error may persist even after applying the official fix:

Permission denied (13)

Root Cause

SELinux is blocking the connection between Amavis and the MariaDB socket. Example audit log:

scontext=system_u:system_r:antivirus_t:s0
tcontext=system_u:object_r:mysqld_db_t:s0
denied { connectto }

This means the Amavis process (running under the antivirus_t context) is not allowed to connect to the MySQL socket. This is not a database or credential issue, but a security policy restriction.

Instead of disabling SELinux, create a policy that explicitly allows this connection:

ausearch -m avc -ts recent | audit2allow -M amavis_mysql
semodule -i amavis_mysql.pp
systemctl restart amavisd
postqueue -f

This approach keeps SELinux enabled and properly extends its policy to support the required communication.

Alternative (TCP Workaround)

If adjusting SELinux policies is not desired, Amavis can be configured to use a TCP connection instead of a Unix socket.

Edit:

/etc/amavisd/email-security.conf

Replace:

mariadb_socket=/var/lib/mysql/mysql.sock

with:

host=127.0.0.1;port=3306

Example:

["DBI:MariaDB:database=emailsecurity;host=127.0.0.1;port=3306","USER","PASS"]

Then restart:

systemctl restart amavisd
postqueue -f

This bypasses the socket permission issue entirely while still keeping the connection local.

Recommendation

  • Apply the official Plesk fix first
  • If the issue persists, implement a SELinux policy
  • Use the TCP workaround as a quick and reliable alternative

Conclusion

If you encounter error (13) when sending emails in Plesk, the underlying issue is typically not related to the database itself but to SELinux blocking access to the MySQL socket. Properly adjusting SELinux or switching to TCP resolves the issue.