Moodle 3.2 PostgreSQL 12 Error reading from database

Moodle 3.2 site started showing error “Error reading from database”.

Moodle 3.2 PostgreSQL error

I checked config.php, the database credentials are correct, i was able to login to Amazon AWS RDS PostgreSQL database with the credentaials and able to see the database tables with command \dt.

psql -h mydb.hwfckmarrpeo.ap-southeast-2.rds.amazonaws.com -p 5432 -U moodle_user -W

I enabled debug in DB with following SQL commands

select * from  mdl_config WHERE name = 'debug';
select * from  mdl_config WHERE name = 'debugdisplay';
UPDATE mdl_config SET VALUE = 2047 WHERE name = 'debug';
UPDATE mdl_config SET VALUE = 1 WHERE name = 'debugdisplay';

But for some reason, moodle did not show any further debug info.

I did a search for the error message “Error reading from database” using ack command, that search inside files.

root@ip-172-31-13-4:/var/www/html# ack "Error reading from database"
lang/en/error.php
216:$string['dmlreadexception'] = 'Error reading from database';
root@ip-172-31-13-4:/var/www/html# ack dmlreadexception
lib/dmllib.php
140:        parent::__construct('dmlreadexception', NULL, $errorinfo);

course/tests/externallib_test.php
1788:            $this->assertEquals('dmlreadexception', $e->errorcode);

lang/en/error.php
216:$string['dmlreadexception'] = 'Error reading from database';
root@ip-172-31-13-4:/var/www/html# 

I added some debug code in file

lib/dmllib.php

That shows the SQL command that caused the failure. The error was

ERROR:  column d.adsrc does not exist

This was because PostgreSQL removed the column name adsrc. To fix, edit file

vi /var/www/html/lib/dml/pgsql_native_moodle_database.php

Find (On line 394)

$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, d.adsrc

Replace with

$sql = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen, a.atttypmod, a.attnotnull, a.atthasdef, pg_get_expr(d.adbin::pg_node_tree, d.adrelid) AS adsrc

For more information on this patch, see MDL-67220

See moodle

Need help with Linux Server or WordPress? We can help!

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *