Intermittent "Error establishing a database connection" in WordPress with Aurora MySQL

0

We are getting an intermittent "Error establishing a database connection" errors we are experiencing in two of our WordPress websites hosted on Amazon Lightsail.

Error Description: The error message displayed in WordPress is: "Error establishing a database connection, contact with the database server could not be established." The error occurs intermittently, affecting roughly 1 in 20 user visits. We haven't observed any significant resource spikes or errors coinciding with the connection failures based on our monitoring tools.

Setup Details:

Troubleshooting Steps Taken:

  • Verified the database connection details in the wp-config.php file (errors here would likely be consistent).
  • Performed a plugin deactivation test to identify any plugin conflicts.
  • Regenerated the .htaccess file and resaved permalinks within WordPress.
  • Purged all website cache.
  • Increased the PHP memory limit to 512MB on the affected instances.
  • Created a new parameter group for the database cluster and adjusted the "aurora_fwd_writer_max_connections_pct" parameter to 90.

Despite these efforts, the intermittent connection errors persist.

asked a year ago1.1K views
1 Answer
0

Hello.

Can I check the web server or PHP error logs?
These logs may contain messages that can help identify the cause of a connection error.
Also, please check the error log on the Aurora side.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.MySQL.LogFileSize.html

profile picture
EXPERT
answered a year ago
  • Thank you for your reply and suggestion to check the web server and Aurora error logs.

    Aurora Error Logs: I've reviewed the Aurora error logs for the past few days, focusing on the time periods when the connection errors occurred. Unfortunately, I haven't found any error messages within the Aurora logs during those specific times.

    Web Server Error Logs: However, the web server error logs on the affected WordPress instances reveal several entries related to the issue. These entries fall into two main categories:

    DNS Resolution Error: The most frequent error message points towards a DNS resolution problem:

    [24-May-2024 01:15:05 UTC] PHP Warning mysqli_real_connect(): php_network_getaddrinfo for XXXX-instance-1.XXXXXX.us-east-1.rds.amazonaws.com failed: Name or service not known in /opt/bitnami/wordpress/wp-includes/class-wpdb.php on line 1987

    This message indicates that the server was unable to resolve the hostname of the Aurora MySQL database

    The other error message suggests a connection failure after the DNS lookup:

    [24-May-2024 01:15:05 UTC] PHP Warning mysqli_real_connect(): (HY000/2002): php_network_getaddrinfo for XXXX-instance-1.XXXXXX.rds.amazonaws.com failed: Name or service not known in /opt/bitnami/wordpress/wp-includes/class-wpdb.php on line 1987

    It seems the issue has something to do with DNS Resolution of the RDS endpoint.

  • It may be due to a large number of name resolutions. I think the setting method will differ depending on the Lightsail OS, but I think it may be improved by configuring DNS cache etc. However, please be aware that caching may prevent switching to work properly in the event of a failover on the Aurora side. https://repost.aws/knowledge-center/dns-resolution-failures-ec2-linux

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions