Sergii Shcherbak
Sergii Shcherbak

Reputation: 977

What happens if JSONField has reached maximum storage limit?

This might be a simple question for an experienced (Django) developer.

My project's database is PostgreSQL.

I intend to use a single protected model instance as a centralised storage for certain data. That instance will have a JSONField which will, in turn, store a dynamic collection of key-value pairs (both are strings). By "dynamic" I mean that new key-value pairs will be added to the collection from time to time, and hence the collection will constantly grow in size.

As far as I have read (e.g. Size limit of JSON data type in PostgreSQL), the size limit of JSONField is approximately 1GB. That is quite a lot, but still not infinite.

My question is: what exactly will happen if I manage to exhaust the storage capacity of JSONField? And are there any recommendations on how to forecast this kind of situation before it happens (e.g. monitor the instance's storage size)?

Upvotes: 2

Views: 4144

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246898

Since you don't plan to manipulate the JSON value in the database, you should use data type json rather than jsonb.

If you exceed that limit, you will get an error message. But since the whole value temporarily has to be kept in RAM on the client side and the database side, I'd expect that you run into problems before that – you'll probably get an out of memory message from the database, or the performance might be really bad.

If you have more than 1GB of state to store in the database, it might be a good idea to split that into several parts and update only those parts that really got changed, like you normally do in a relational database.

Upvotes: 4

itzMEonTV
itzMEonTV

Reputation: 20349

Here is almost you wanted.

Upvotes: 1

Related Questions