0

I upgraded a Debian 9 "Stretch" server to Debian 10 "Buster", which also upgrades Mediawiki to version 1.31.

Trying to run update.php, it fails with "Cannot access the database: No database connection":

/var/lib/mediawiki/maintenance# php update.php
MediaWiki 1.31.10 Updater

Your composer.lock file is up to date with current dependencies!
[6b70dd5bdc9deadcca99506a] [no req]   Wikimedia\Rdbms\DBConnectionError from line 1004 of /usr/share/mediawiki/includes/libs/rdbms/database/Database.php: Cannot access the database: No database connection
Backtrace:
#0 /usr/share/mediawiki/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1140): Wikimedia\Rdbms\Database->reportConnectionError(string)
#1 /usr/share/mediawiki/includes/libs/rdbms/loadbalancer/LoadBalancer.php(750): Wikimedia\Rdbms\LoadBalancer->reportConnectionError()
#2 /usr/share/mediawiki/includes/GlobalFunctions.php(2813): Wikimedia\Rdbms\LoadBalancer->getConnection(integer, array, boolean)
#3 /usr/share/mediawiki/maintenance/Maintenance.php(1311): wfGetDB(integer, array, boolean)
#4 /usr/share/mediawiki/maintenance/update.php(147): Maintenance->getDB(integer)
#5 /usr/share/mediawiki/maintenance/doMaintenance.php(94): UpdateMediaWiki->execute()
#6 /usr/share/mediawiki/maintenance/update.php(248): require_once(string)
#7 {main}

The database is Postgresql, and I can access it fine with psql etc.

In LocalSettings.php I have

## Database settings
$wgDBtype           = "postgres";
$wgDBserver         = "localhost";
$wgDBname           = "wikidb";
$wgDBuser           = "...";
$wgDBpassword       = "...";

# Postgres specific settings
$wgDBport           = "5432";
$wgDBmwschema       = "mediawiki";
$wgDBts2schema      = "public";

In the Mediawiki debug log, I also see

IP: 127.0.0.1
Start command line script update.php
[caches] cluster: EmptyBagOStuff, WAN: mediawiki-main-default, stash: db-replicated, message: SqlBagOStuff, session: SqlBagOStuff
[caches] LocalisationCache: using store LCStoreNull
[DBConnection] Wikimedia\Rdbms\LoadBalancer::openConnection: calling initLB() before first connection.
[DBReplication] Wikimedia\Rdbms\LBFactory::getChronologyProtector: using request info {
    "IPAddress": "127.0.0.1",
    "UserAgent": false,
    "ChronologyProtection": false,
    "ChronologyPositionIndex": 0
}
[DBConnection] Wikimedia\Rdbms\LoadBalancer::openConnection: failed to connect to database 0 at 'localhost'.
[DBConnection] Wikimedia\Rdbms\LoadBalancer::reportConnectionError: connection error: Unknown error ([Null])
[exception] [6b70dd5bdc9deadcca99506a] [no req]   Wikimedia\Rdbms\DBConnectionError from line 1004 of /usr/share/mediawiki/includes/libs/rdbms/d
atabase/Database.php: Cannot access the database: No database connection

I'm now completely stuck...

mivk
  • 4,004
  • 3
  • 37
  • 32
  • can you connect to the database using psql? What does "pg_lsclusters" say? Did you upgrade/migrate your databases to the newer version? – wazoox Nov 05 '21 at 17:51

3 Answers3

2

Try commenting out:

$wgDBmwschema       = "mediawiki";
$wgDBts2schema      = "public";

The first setting's default value has changed; the second is obsolete.

1

For newer mediawiki versions, there are some pitfalls that breaks the mysql connection. Some attempts to fix are:

  1. Insert the port number on Database Host:
$wgDBserver = "localhost:3306";
  1. On some old LocalSettings.php, there are active configurations for PostgreSQL besides the Mysql config. Erase or comment it.
# Postgres specific settings
# $wgDBport           = "5432";
# $wgDBmwschema       = "mediawiki";
# $wgDBts2schema      = "public";
  1. As a good practice, make sure you are not connecting as root on mysql. Create a regular user just for the wikidb database:
$mysql -u root -p
> create user wiki identified by 'xxxx';
> grant all privileges on wikidb.* to 'wiki'@'localhost';
Josir
  • 141
  • 6
  • 1
    My problem was the leftover postgresql-specific configs (the `wgDBmwschema and `wgDBts2schema` settings). Thanks, this was driving me insane. – Christopher Schultz Mar 27 '23 at 19:07
1

The problem turned out to be that the system upgraded PHP, but did not re-install or re-enable the php pgsql module for Postgres.

The same problem appeared again when upgrading from Debian 10 to Debian 11, and was solved by

apt install php7.4-pgsql

I guess this will happen again when I upgrade to Debian 12.

mivk
  • 4,004
  • 3
  • 37
  • 32