Big jump in User ID

Big jump in User ID

by Mick Smith -
Number of replies: 3

Hi Everyone,


Hopefully someone can help.

I've just noticed that on one of our Moodle installs, the user ID of new accounts has jumped to a much larger number.

Looking at the mdl_user, all id's are sequential from 0 up to 9537, then the next account created after that is 500243593.  And all accounts created after that are continuing from 500243593

We don't have any hacks to the core code.  Has anyone else experienced this issue before and able to offer assistance?

Moodle 3.8.4+

Many Thanks

Average of ratings: -
In reply to Mick Smith

Re: Big jump in User ID

by Mick Smith -
A wee update for anyone thats able to help with this....
I think its down to a rogue csv that was uploaded by one of the admins back in March. Is there away to reset the automatic user ID moodle creates to a lower number?
In reply to Mick Smith

Re: Big jump in User ID

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

If this is the mdl_user.id column this isn't managed or incremented by Moodle, it's the database software which does this.

Whether and how this can be reset would depend on the database software, MySQL, MariaDB, PostgreSQL or SQL Server.

With MySQL 5.7 and earlier, the counter gets reset to the highest value present + 1 when MySQL is restarted. For example:

  1.     If you inserted 200 rows into a table the next id would be 201.
  2.     If you deleted the last 100 rows the next id would still be 201.

But:

  1.     If you inserted 200 rows into a table the next id would be 201.
  2.     If you deleted the last 100 rows and then restarted MySQL (assuming version 5.7).
  3.     Now the counter is reset and the next id would be 101.

So if you were using MySQL 5.7 or earlier and deleted the rows from mdl_user (not just deleting them from Moodle as this doesn't actually remove the rows) then restarting MySQL should reset the counter.

However in MySQL 8.0 and later (and MariaDB 10.2.4 and later), restarting doesn't reset this counter. MariaDB also has SET insert_id which may be useful.

I'm less familiar with PostgreSQL and SQL Server so I don't know about resetting these counters off the top of my head.

If you were looking to change these I'd recommend 1) making sure there was a database backup and 2) trying this on a test system first to make sure it works as expected.

In reply to Leon Stringer

Re: Big jump in User ID

by Mick Smith -
Thanks for replying Leon, I tried ALTER TABLE mdl_user AUTO_INCREMENT = VALUE on a test database, but as you stated, MYSQL will still set the value as highest value present + 1. I'm not wanting to mess around with the current users id's, the high id's shouldnt cause any issue. I was just shocked when I noticed them in the first place. Thanks for your assistance!