O
O
oleg_ru2020-05-18 08:16:19
Database
oleg_ru, 2020-05-18 08:16:19

Do DBMSs save hard disk space compared to storing (small) data in json files?

If we store a small dictionary in the settings.json file, then by loading it into memory and changing one of the values ​​in it, we must overwrite the entire file in order to save the changes. If we have a settings table in the database and change one row in it, will only that row or the entire table be physically overwritten? when using:
1.1) sqlite
1.2) Postgresql

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Armenian Radio, 2020-05-18
@gbg

we have to overwrite the entire file
If you look from this side, then yes, both JSON and XML are absolutely stupid formats when it comes to storing data in the process of processing it - it is worth changing one field, and you need to rewrite the entire tail of the file, since all records are of variable length.
On the other hand, DBMSs store their data in so-called pages , which are usually a multiple of the hard disk cluster size. Therefore, changing a single entry will only overwrite the group of pages associated with that entry, not overwrite the entire database.
However, from a practical point of view, it is important to look not at wear, but at speed. A DBMS, for example, stores numbers in binary representation, while JSON, XML, and others require converting numbers to strings and vice versa with each write and read, which naturally creates additional brakes and warms the atmosphere.
Designing software taking into account the possible wear of data drives is already an attempt to take into account third-order effects (first order - software works with errors, second order - works correctly but slowly, third - works quickly and correctly, but creates indirect costs for equipment), which has little practical sense.
That is, yes, storing data in a DBMS is more optimal and faster. There is also a data schema that will monitor their integrity, as well as filtering and aggregation functionality that you don’t have to write again.

S
Sergey Gornostaev, 2020-05-18
@sergey-gornostaev

If we have a settings table in the database and change one row in it, will only that row or the entire table be physically overwritten?

A block of some size will be overwritten. It can be larger than the data in the line, but in any case, it is significantly less than the size of the entire file.

R
rPman, 2020-05-18
@rPman

It all depends on the size of this file, and most importantly, do you need atomic transactions (this is necessary for multi-user write and read access), since when using them, the overhead of writing to the database increases SIGNIFICANTLY, and possibly up to 4-8 kilobytes (1 filesystem extent) it is more efficient to store and overwrite the file in its pure form without a database (although you will have to monitor the locks yourself).
If you have only reading, then without any options, work with your file (not necessarily json, it is more interesting to store it as a php code, to save data in this form, use var_dump/var_export, this is the fastest and most efficient in terms of CPU load). even a hundred kilobytes in its file can be more efficient than storing dictionaries in the database, especially since it will be perfectly cached at the OS level.
The inconvenience of storing dictionaries in a file is not a uniform method of working with data, if part of the data is in your database and part is in files, you will have to support both methods and not just one.

P
Puma Thailand, 2020-05-18
@opium

Taking into account the fact that the warranty on disks is now three years, the question does not make sense. That and that case will not have time to work out the server resource

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question