Data size increases when updating

I was doing a CRUD test.
However, I found that the size of the data file increased during the update.
What’s the reason?

[before update]
$ ll /data
total 24494284
drwxr-xr-x 3 root root 4096 Dec 1 11:39 ./
drwxr-xr-x 5 root root 4096 Dec 1 09:54 …/
-rw------- 1 root root 24147849216 Dec 1 11:39 collection-7-7580962752483617836.wt
. . .

[after update]
$ ll /data
total 28553944
drwxr-xr-x 3 root root 4096 Dec 1 11:39 ./
drwxr-xr-x 5 root root 4096 Dec 1 09:54 …/
-rw------- 1 root root 28176080896 Dec 1 11:39 collection-7-7580962752483617836.wt
. . .

What I think:
This is because mongodb stores documents before change.

1 Like

Hi @Kim_Hakseon,

When data is committed to disk via a checkpoint, the WiredTiger storage engine needs to write the latest version of data before freeing unused pages associated with the previous checkpoint. This is described in Snapshots and Checkpoints in the MongoDB server documentation:

During the write of a new checkpoint, the previous checkpoint is still valid. As such, even if MongoDB terminates or encounters an error while writing a new checkpoint, upon restart, MongoDB can recover from the last valid checkpoint.

The new checkpoint becomes accessible and permanent when WiredTiger’s metadata table is atomically updated to reference the new checkpoint. Once the new checkpoint is accessible, WiredTiger frees pages from the old checkpoints.

Previously allocated space will be reused where possible per the Storage FAQ:

The WiredTiger storage engine maintains lists of empty records in data files as it deletes documents. This space can be reused by WiredTiger, but will not be returned to the operating system unless under very specific circumstances.

Regards,
Stennie

1 Like

I understood it at once.
Can I ask you one more question?

I gave 6 million update commands to mongodb containing 20 million (23GB) of data (about 1KB per document).
But this 23GB became 57GB.
As far as I know, It need 6GB of extra space. But this was concluded that it needed more than twice the space.

May I know why?

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.