- Newest
- Most votes
- Most comments
Thank you for reaching out regarding the performance and database connectivity issues with your WordPress Lightsail instance. I understand how critical this is for your site's availability.
Based on the "Error establishing a database connection" message you're seeing, this typically indicates that WordPress cannot communicate with the MySQL/MariaDB database service. Here are some steps to help diagnose and resolve this issue:
Immediate Diagnostic Steps via SSH:
- Check if the database service is running:
- Connect via SSH and run:
sudo systemctl status mariadborsudo systemctl status mysql - If the service is stopped, start it with:
sudo systemctl start mariadborsudo systemctl start mysql
- Review database error logs:
- Check MariaDB/MySQL logs at:
/var/log/mysql/error.logor/var/log/mariadb/mariadb.log - These logs will reveal if the database is crashing due to resource constraints or corruption
- Verify database credentials:
- Ensure your
wp-config.phpfile has the correct database name, username, and password - The file is typically located at
/opt/bitnami/wordpress/wp-config.phpor similar path depending on your stack
- Check available disk space:
- Run:
df -hto verify you haven't run out of disk space, which can prevent the database from starting
Resource Considerations:
The extreme latency and timeouts you're experiencing suggest your instance may be undersized for your workload. Consider:
- Reviewing your instance's CPU and memory utilization in the Lightsail metrics
- Upgrading to a larger instance plan if resources are consistently maxed out
- Optimizing your WordPress installation (plugins, caching, database optimization)
Next Steps:
If the database service won't start or logs indicate corruption, you may need to:
- Create a snapshot of your current instance before making changes
- Attempt database repair using MySQL repair tools
- Consider restoring from a previous snapshot if you have one from when the site was working
For detailed technical assistance with your specific instance configuration and logs, please add this information as correspondence in the AWS Support Center at https://console.aws.amazon.com/support/, where the support team can review your instance-specific details and provide targeted guidance based on your AWS Support plan.
Hello,
Can you confirm if you are using the smallest bundle size for your wordpress instance and also the disk is full? if so, The likely root cause is becuase A nano instance is undersized for WordPress + MariaDB running together. Over time, as the site accumulates content, plugins, and traffic, MariaDB gets OOM-killed. It's recommend to upgrade to larger instance.
- command to check your disk usage.
df -h
Hi Usman,
The symptoms you're describing — "Error establishing a database connection," extreme latency, and instability after reboots — are consistent with your instance running out of memory. When this happens, the Linux kernel terminates the MariaDB database process to free memory (called an "OOM kill"), which causes the database connection error you're seeing. Rebooting temporarily restarts MariaDB, but it gets killed again once memory is exhausted.
Step 1: Confirm the issue
Connect to your instance via SSH and run:
sudo dmesg | grep -i "out of memory"
If you see entries like Out of memory: Killed process ... (mariadbd), this confirms memory pressure is the root cause.
You can also check how much memory is currently available:
free -m
Look at the available column — if it's below about 50 MB, your instance is critically low on memory.
Step 2: Restart MariaDB (immediate fix)
If your site is currently down:
sudo systemctl restart mariadb
sudo systemctl status mariadb
If the status shows Active: active (running), your site should come back up — but this is temporary if memory pressure is the underlying cause.
Step 3: Add swap space (prevents future OOM kills)
Check if swap is already enabled:
cat /proc/swaps
If no swap is configured, create one:
sudo dd if=/dev/zero of=/mnt/.lightsail.swap bs=1K count=665600 status=progress
sudo chmod 600 /mnt/.lightsail.swap
sudo mkswap /mnt/.lightsail.swap
sudo swapon /mnt/.lightsail.swap
echo '/mnt/.lightsail.swap none swap sw 0 0' | sudo tee -a /etc/fstab
Step 4: Tune MariaDB memory usage
The default innodb_buffer_pool_size may be too large for your instance. Check your instance's total memory with free -m, then create this configuration file:
sudo tee /etc/mysql/mariadb.conf.d/90-lightsail-memory.cnf > /dev/null <<'EOF'
[mysqld]
innodb_buffer_pool_size = 16M
EOF
sudo systemctl restart mariadb
(Use 16M for instances up to ~1.5 GB RAM, 256M for 2–4 GB RAM.)
Step 5: Tune Apache worker processes
sudo tee /etc/apache2/mods-available/mpm_prefork.conf > /dev/null <<'EOF'
<IfModule mpm_prefork_module>
StartServers 1
MinSpareServers 1
MaxSpareServers 3
MaxRequestWorkers 5
MaxConnectionsPerChild 5000
</IfModule>
EOF
sudo systemctl restart apache2
(Use MaxRequestWorkers 5 for instances up to ~1.5 GB, 10 for 2–4 GB.)
Best regards
Relevant content
asked 3 years ago
- AWS OFFICIALUpdated 2 months ago

Technical Support Request: WordPress Instance (13.235.224.140) - Database Service Running but Connection Error Persists Dear AWS Support Team,
Following up on my previous request regarding the "Error establishing a database connection" on my instance (13.235.224.140), I have performed further diagnostic checks via the SSH terminal.
New Findings: I ran sudo systemctl status mariadb and confirmed that the database service is active (running) and currently "Taking your SQL requests now." Despite this, the WordPress application remains unable to connect to the database.
Diagnostics:
Database Status: Verified active (running). Logs: The MariaDB service shows no recent crash logs. Current Issue: The application consistently throws an "Error establishing a database connection" message (see previously attached screenshot: "Wordpress server loading issue.JPG"). Since the database engine is confirmed to be healthy, the issue likely resides in the wp-config.php credentials or a socket mismatch between the application and the database service. Could you please assist by: Verifying if the database user permissions or the localhost socket path in my wp-config.php file are correctly aligned with the current MariaDB configuration? Advising if there is a conflict in the database host setting (i.e., should it be 127.0.0.1 instead of localhost?). Directing me to the specific logs that capture the application's attempt to reach the database (e.g., PHP-FPM or Apache error logs).