2

I would like to see the size of the database I created with django. This is for a project. How do I go about that? I have looked at stackoverflow answers, and I found this answer:

$ python manage.py shell

>>> import sys
>>> from myapp.models import MyModel
>>> my_model = MyModel()
>>> total_size = sys.getsizeof(my_model) * MyModel.objects.count()

This however always gives a size of 24 bytes, while the tables I put into it have completely different amounts of fields. I suspect this is wrong.

Thanks in advance.

Jens
  • 141
  • 10
  • 1
    with SQL you can check how many rows you have - but to get how many bytes it uses on disk you should rather find file with all data and check its size without using `Python` – furas May 14 '20 at 11:13
  • 1
    using Google "mysql size on disk" I found SQL queries [MySQL / MariaDB: Show disk usage of tables and columns](https://makandracards.com/makandra/39413-mysql-mariadb-show-disk-usage-of-tables-and-columns) and [How to get the sizes of the tables of a MySQL database?](https://stackoverflow.com/questions/9620198/how-to-get-the-sizes-of-the-tables-of-a-mysql-database) – furas May 14 '20 at 11:17
  • Thank you for answering! I just saw I made a mistake, the database isnt't based on MySQL, it is instead based on sqlite3. – Jens May 14 '20 at 12:27
  • 1
    if it is sqlite then you should see file with data in django's project and check its size without django/python – furas May 14 '20 at 12:30
  • I checked the size with sqlite analyzer from sqlite.org, but I get these values. I am unsure what they mean: Percentage of total database...................... 10.5% Number of entries................................. 48 Bytes of storage consumed......................... 16384 Bytes of payload.................................. 1095 Since this is an entry to the table that uses multiple charfields and textfields 1095 seems really small. If I add 4 entries instead of 48 the storage consumed stays at 16384 which confuses me also. The documentation has made me none the wiser. – Jens May 14 '20 at 16:32
  • 1
    why don't you check normally file size on disk - ie. `print( os.stat(filename).st_size )` – furas May 14 '20 at 16:41
  • Oh, so you can just check the file size of the 'db.sqlite3' file django makes and you get how much diskspace your database uses? I did not know that. Thanks!! – Jens May 14 '20 at 17:04
  • 1
    all databases keep data in some file - but only SQLite creates it in current folder and you can easily access it. For other databases you would have to find this file in different folder but if database is on other server then you may not have access to file. – furas May 14 '20 at 17:30

0 Answers0