Have many "deleted" students in database

Have many "deleted" students in database

by Fred Frazelle -
Number of replies: 8

Hello!

Was checking my moodle database today and see that mdl_usr table has some 950 entries which have been marked as "deleted" but which still exist.  Is there any manner in which i can eliminate these entries without doing this on a one-by-one basis (using the little "Delete" button for each one).  i have access to the Pgsql database through my webhosting and a phpPgAdmin button.

We are using the most recent, 3.10 version of Moodle

Thanks for your help, stay safe and have a beautiful day!   smile

Average of ratings: -
In reply to Fred Frazelle

Re: Have many "deleted" students in database

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You should leave them alone. It's intentional - it's the way Moodle handles deleted users.

Consider - what would happen if one of those people had posted halfway through a forum thread and you deleted the record?
In reply to Howard Miller

Re: Have many "deleted" students in database

by Fred Frazelle -
Dear Howard - thank you so much for such a quick reply!

These are students which are no longer enrolled. We would like to purge them from the database. How can we accomplish this?

Please be happy, stay safe and have a radiant evening! smile
In reply to Fred Frazelle

Re: Have many "deleted" students in database

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Why?

You might want to have a look at Data_privacy
In reply to Howard Miller

Re: Have many "deleted" students in database

by Fred Frazelle -
Deletion of user data

When a user's data is deleted, any forum posts are blanked and replaced with a sentence stating that the post has been removed. However, if the user started any discussions, their name is currently still shown on the forum page (MDL-62865).

Our site does not have a Forum.


(Edited by Howard Miller to remove signature - original submission Friday, 22 January 2021, 3:53 PM)

In reply to Fred Frazelle

Re: Have many "deleted" students in database

by Fred Frazelle -
Went to the Riot software for irc chats and conntected #postgresql where i posted the same question and in less that 30 seconds got an answer to the question.

DELETE FROM mdl_user WHERE deleted = 1, which i promptly pasted into the window in my phpAdmin site and voila! 950 fewer students! Yeah!!!

So, thanks for helping and have a beautiful day! smile
Average of ratings: Useful (1)
In reply to Fred Frazelle

Re: Have many "deleted" students in database

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes - they told you how to delete all the records from mdl_user where deleted was equal to 1.

But that isn't what you asked how to do. You know best of course...   you can probably look forward to the weird errors having broken lots of database relationships.
Average of ratings: Useful (1)
In reply to Fred Frazelle

Re: Have many "deleted" students in database

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Not only does Howard have a point, but in my experience I found that taking a backup of a database before deleting any users to be a most useful exercise. Also, our Education Data laws are a little different in that we have to keep all records of students available for decades after they have left an education institution. This allows former students to be able to access their own records for employment applications, receive duplicate certificates if the originals are lost or destroyed, and other options.
Alternatively, I always have a backup to restore if the dbase all of a sudden decides not to work because I have deleted something I shouldn't have.
Average of ratings: Useful (1)
In reply to Colin Fraser

Re: Have many "deleted" students in database

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
To the casual reader who stumbles across this in the future - please let me be quite clear. Do NOT delete records out of your database unless you *really* know what you are doing (and as Colin says, take a backup even then). Fred does not know what he is doing.