How to Get Android Room Database Size

When we’re developing an Android application with Room for the local database, we might want to know how much space our database is taking.

Here’s a simple way to do it:

The main idea of the above utility class is pretty simple: Find out the file size of our Room database file.

The tricky part is getting the directory/folder in which the Room database file resides. Although Room database file is located in the same partition as internal storage, it is located in different folder:

  • Internal storage resides in files folder.
  • Room database file resides in databases folder.

I managed to get the database folder by replacing files with databases (line 17 in the Gist above). I tested this on Android Lollipop & Android 11 and got positive results. (Let me know if this trick doesn’t work on your device!)

Once we got the database folder, we can simply get the file size by calling length() method (line 23).

Here’s an example of using DatabaseUtil in your Activity:

Let me know what you think of this method or whether you have a better way of getting Room database size.

As always, thanks for reading!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store