Wordpress often loses database connection (mariadb on its own container)

Hi there

I wonder if you have a few tips on how to minimise issues with wordpress and mariadb on fly.io

I keep getting “database connection error” while using the Wordpress admin UI, but I can make changes, so I don’t think it’s a problem with authentication.

I’ve got one container and one volume for each (wp and mariadb), and both are using official docker images.

The wordpress is configurated with my-maria-container.internal as host.

I’ve upped both to 512MB RAM, and looking at the monitor screens it’s doesn’t seem to exceed this limit.

What else could be wrong with my setup?

Is MariaDB listening on ipv6?

The mariaDB container has no IPs assigned. The WP container has both IPV4 and IPV6.

To check if mariadb is listening on ipv6 on the internal ip address, do the following. Note you may need to install lsof.

$ fly ssh console -a mariadb
root@dd13b6eb:/# lsof -ni |grep LISTEN
beam.smp 515 nobody   18u  IPv6   4561      0t0  TCP *:37541 (LISTEN)
beam.smp 515 nobody   30u  IPv6   4611      0t0  TCP *:4000 (LISTEN)
hallpass 516   root    6u  IPv6   4376      0t0  TCP [fdaa:0:7bb8:a7b:b389:dd13:b6eb:2]:22 (LISTEN)
epmd     563 nobody    3u  IPv4   4453      0t0  TCP *:4369 (LISTEN)
epmd     563 nobody    4u  IPv6   4454      0t0  TCP *:4369 (LISTEN)

1 Like

Thank you for taking your time with this!

I had lsof and this is the output:

# lsof -ni |grep LISTEN
mariadbd 523 mysql   20u  IPv4    4521      0t0  TCP *:mysql (LISTEN)
mariadbd 523 mysql   21u  IPv6    4522      0t0  TCP *:mysql (LISTEN)
hallpass 524  root    6u  IPv6    4418      0t0  TCP [fdaa:0:9f75:a7b:caca:1:e3b3:2]:ssh (LISTEN)

ok, now we need to check connectivity from your wordpress container.

$ fly ssh console -a wordpress
# mysql -u someuser -h mariadb.internal -p

What am I supposed to put in as “mysql”? I’ve tried “mysql”, “mariadb”, “maria”, and the container name. I get “not found”.

You need to install the mysql client. The following is on a ubuntu container.

root@779be656:/# apt-get update
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 Packages [8,184 kB]
Get:4 http://security.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Get:5 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2,596 B]
Get:6 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [183 kB]
Fetched 8,578 kB in 1s (7,053 kB/s)                  
Reading package lists... Done

root@779be656:/# apt-cache search mysql client
golang-github-ziutek-mymysql-dev - MySQL Client API
mariadb-client-10.5 - MariaDB database client binaries
mariadb-client-core-10.5 - MariaDB database core client binaries
mypager - pager for MySQL/PostgreSQL command line clients
default-libmysqlclient-dev - MySQL database development files (metapackage)
default-mysql-client - MySQL database client binaries (metapackage)
default-mysql-client-core - MySQL database core client binaries (metapackage)
node-mysql - MySQL client implementation for Node.js
librust-mysqlclient-sys-dev - Auto-generated rust bindings for libmysqlclient - Rust source code


root@779be656:/# apt-get install default-mysql-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libbsd0 libconfig-inifiles-perl libdbd-mariadb-perl libdbi-perl libedit2 libgdbm-compat4
  libgdbm6 libmariadb3 libmd0 libncurses6 libperl5.32 libterm-readkey-perl
  mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common mysql-common netbase perl
  perl-base perl-modules-5.32
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl gdbm-l10n
  sensible-utils perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make
  libtap-harness-archive-perl
The following NEW packages will be installed:
  default-mysql-client libbsd0 libconfig-inifiles-perl libdbd-mariadb-perl libdbi-perl
  libedit2 libgdbm-compat4 libgdbm6 libmariadb3 libmd0 libncurses6 libperl5.32
  libterm-readkey-perl mariadb-client-10.5 mariadb-client-core-10.5 mariadb-common
  mysql-common netbase perl perl-modules-5.32
The following packages will be upgraded:
  perl-base
1 upgraded, 20 newly installed, 0 to remove and 37 not upgraded.
Need to get 12.8 MB of archives.
After this operation, 87.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
....more output...


root@779be656:/# mysql --version
mysql  Ver 15.1 Distrib 10.5.15-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper


1 Like

Thanks! Done and done

# mysql --version
mysql  Ver 15.1 Distrib 10.5.15-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

Then I used the db user according to the wp config and got this:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 500
Server version: 10.9.2-MariaDB-1:10.9.2+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

So to confirm, you were on the wordpress container and used the mysql cli to connect to the mariadb container? It seems like everything is working correctly?

I’m not sure I understand what “but I can make changes” means. Maybe this isn’t a database issue?

Yes. I had signed into the wp container and connected to Maria DB.

My issue is that I can indeed, log into Wordpress, and I can edit settings and update themes, etc, but every time I do so, I get a “connection error” message and have to reload the page. Except yesterday when I also started to get continuous 500 errors.

The DB connection seems fine, but this error seems to hint at some connectivity issue, just not authentication issue. Wordpress lists this error possibly due to “wrong db credentials”, “db timeout”, or “corrupt db tables”.

Well, it’s not “wrong db credentials” or “db timeout”. Maybe it is “corrupt db tables”? Not sure where to go from here, but perhaps the next step is to try a clean install.

Hmmm, it’s a fresh install, but I’ll see if I can ‘repair’ the tables first, then a fresh install perhaps with some optimisations I read in this fly.io thread.

Tried repair mode, by adding define ('WP_ALLOW_REPAIR', true); to wp-config and then visiting wp-admin/maint/repair.php in the web browser.

It was difficult because I got “Cannot establish database connection” for every action I took.

Tried “repair and optimise”, and got this for every table:

Failed to optimise the ias_usermeta table. Error: Table does not support optimize, doing recreate + analyze instead

Afterwards, I immediately got the same connection error message :stuck_out_tongue:

Update: not sure how to rebuild tables without PhpMyAdmin, but I tried redeploying with optimisation new values in CMD, but couldn’t start the instance due to “allocation errors”. Maybe the volume needs to be killed? Removed the settings and could finish deployment, but still have the same errors as before…

Update: I set the debug flag in Wordpress and now receive the exposed error:

Warning: mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /var/www/html/wp-includes/wp-db.php on line 1753 Warning: mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /var/www/html/wp-includes/wp-db.php on line 1753

php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Update, I added some optimisation options to the DB vars and seemed to be fast at first but went back to network errors… Here’s the DB TOML:

# fly.toml file generated for wp-maria on 2022-09-13T16:41:11+02:00

app = "wp-maria"
kill_signal = "SIGINT"
kill_timeout = 5

[mounts]
  source = "mariadata"
  destination = "/data"

[env]
  MARIADB_DATABASE = "wordpress"
  MARIADB_USER = REDACTED

[build]
  image = "mariadb:10"

[experimental]
  cmd = [
    "--datadir","/data/maria",
    "--innodb_buffer_pool_size", "400M", <-- 80% of total RAM
    "--query_cache_type", "1",
    "--query_cache_limit", "5M", <-- based on some guide where the total RAM was 1G and this value 10M
    "--query_cache_size", "40M" <-- based on some guide where the total RAM was 1G and this value 80M
  ]

When changing the cache values and redeploying the DB, the site is initially very fast, then goes back to unresponsive.

I’m really struggling with this. No idea what to look for, and the dollar counter is just going up.

Rudely bumping thread for attention.