How can I fix the error: unable to connect to DSN 'DBI:MariaDB:database=danami_warden;host=localhost'?

Overview

This article provides resolution steps for the Amavis error indicating a failure to connect to the MariaDB database via DSN. This issue typically occurs on RPM-based systems running MariaDB 10.5 or newer with SELinux enabled, or when Warden configuration credentials become corrupted.

Error Identification

The following error message appears in the system mail logs:

Jan 1 03:30:45 busy-gates amavis[18902]: (18902-01) (!)connect_to_sql: unable to connect to DSN 'DBI:MariaDB:database=danami_warden;host=localhost': Can't connect to local server through socket '/var/lib/mysql/mysql.sock' (13) Jan 1 03:30:45 busy-gates amavis[18902]: (18902-01) (!!)TROUBLE in check_mail: gen_mail_id FAILED: connect_to_sql: unable to connect to any dataset at (eval 100) line 253.

Resolution Steps

Select the appropriate procedure based on your environment and configuration state.

SELinux Context Misconfiguration

This error is frequently caused by an incorrect SELinux context applied to the MariaDB socket file. A known issue in certain MariaDB RPM packages (MDEV-24941) prevents the correct security context from being assigned, resulting in a permission denied error (code 13) when services attempt to connect.

To resolve this issue, execute the following commands with root or sudo privileges:

semanage fcontext -a -t mysqld_exec_t -s system_u "/usr/sbin/mariadbd"
restorecon -v /usr/sbin/mariadbd
systemctl restart mariadb

These commands apply the correct SELinux context to the MariaDB binary and restart the service. This workaround remains effective until upstream RPM packages are updated.

Corrupted Database Credentials

If SELinux is not the root cause, the error may indicate missing or corrupted database credentials within the Warden configuration. Resetting these credentials will restore proper connectivity.

Run the following commands to reset the Amavis and SpamAssassin learning database credentials:

// reset the Amavis database credentials
warden --task=contentfilter:contentfilter --default=yes --reload=yes

// reset the SpamAssassin learning database credentials
warden --task=antispam:learning --default=yes --reload

Troubleshooting & Verification

After applying the relevant fix, verify that the issue is resolved by monitoring the mail logs for successful connection attempts. Ensure that the MariaDB service is active and listening on the expected socket path /var/lib/mysql/mysql.sock. If connectivity issues persist, confirm that local network configurations or firewall rules are not blocking localhost database connections.

  • selinux, socket
  • 0 Użytkownicy uznali to za przydatne
Czy ta odpowiedź była pomocna?

Powiązane artykuły

How can I fix the error: Host '127.0.0.1' is not allowed to connect to this MariaDB server?

Overview This article provides resolution steps for the MariaDB connection error Host...

How can I fix the error: Parse error at /etc/clamav/clamd.conf Unknown option ScanImage?

Overview The clamav-daemon.service may fail to start due to unrecognized configuration...

How can I fix the error: The domain limit of this license key has been reached?

Overview The Admin and Pro editions of Danami products enforce a maximum domain limit within the...

After upgrading from Centos 7 to AlmaLinux 8 Amavis is treating mail with low scores as spam. How can I fix this?

Overview Following an upgrade from CentOS 7 to AlmaLinux 8, Amavis may incorrectly classify...