If you’ve also encountered this annoying error, you’ve come to the right place. I encountered this error within msfconsole, as I noticed it was taking a very long time to open, sitting at 100% CPU and being unable to run basic tasks such as searching within Metasploit after running sudo apt update and sudo apt upgrade.
The searches I did find online lead to uninformative posts that lead me down a rabbit hole. After some further testing and attempting to open Metasploit Database and rebuild the database, I ran in to the underlying issue:
WARNING: database "postgres" has a collation version mismatch
DETAIL: The database was created using collation version 2.38, but the operating system provides version 2.40.
HINT: Rebuild all objects in this database that use the default collation and run ALTER DATABASE postgres REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.

After some frustrations and hours of searching on how to perform this postgres database rebuild with no information pointing towards Metasploit, I found the solution within the Try Hack Me community.
The Fix
By running the following command:
sudo -u postgres psql -c "ALTER DATABASE postgres REFRESH COLLATION VERSION;"
Then running:
sudo service postgresql restart
This will update the collation database version Metasploit uses and restarts the postgresql service. Once you do this, Metasploit should load faster, not use 100% CPU and searches will work again!
I hope this was informative, and I will be releasing more blogposts like this in future to assist in resolving issues such as this. Feel free to comment if you found this useful, any feedback is greatly appreciated.