Tag: moodle

  • How to find Moodle version from Database

    How to find Moodle version from Database

    Sometimes you may need to find what version of Moodle database you have. To find the version of moodle from the database, check in table mdl_config

    SELECT * FROM `mdl_config` WHERE `name` LIKE '%release%';
    SELECT * FROM `mdl_config` WHERE `name` LIKE '%version%';
    

    These SQL commands will give information about the version of Moodle you are using.

    Moodle version from database table

    On a Moodle server, after the upgrade release changed to the new version, backup_release show older version

    MariaDB [moodle]> select * from mdl_config where `name` like "%release%";
    +-----+----------------+---------------------------+
    | id  | name           | value                     |
    +-----+----------------+---------------------------+
    |   9 | backup_release | 3.9                       |
    | 417 | release        | 3.10.11 (Build: 20220509) |
    +-----+----------------+---------------------------+
    2 rows in set (0.000 sec)
    
    MariaDB [moodle]> 
    

    Finding Moodle Version from files

    Moodle includes a file in the root directory with the name Version.php, this file contains Moodle version.

    See Moodle

  • Moodle 3.2 PostgreSQL 12 Error reading from database

    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