Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roughly how fast is JSON -> JSONB column conversion in Postgres 9.4

I'm looking to migrate from Postgres 9.3 to 9.4, and have a lot of data in JSON columns. While it's fine, I wanted to have a look at migrating to the more efficient column storage (which JSONB seems to be — a really exciting piece of tech!).

To actually migrate, I want to know migration characteristics for something like

ALTER TABLE table_with_json
    ALTER COLUMN my_json
    SET DATA TYPE jsonb
    USING my_json::jsonb;

(from this helpful question).

Ideally, it would be good to know how long it takes to migrate 1mil and 10mil entries, and how it scales.

While I can get these numbers myself, I thought this question might be helpful for others. If I end up trying this out myself, I'll be sure to provide an answer for others, but not sure when that'll happen.

like image 436
gregoltsov Avatar asked Dec 02 '15 12:12

gregoltsov


2 Answers

Migrating from JSON to JSONB took 282 seconds. It basically matches the time required to insert data with an SQL INSERT.

Testing environment:

  • PostgreSQL 9.5
  • 4 cores, 16GB RAM
  • 2KB/row of JSON content
  • 5.2 million rows
like image 118
Boris Schegolev Avatar answered Oct 23 '22 21:10

Boris Schegolev


Some back-of-the napkin numbers for a test instance migration:

  • PostrgeSQL 9.6
  • 2 vcpu cores, 8GB RAM, EBS max bandwith 450 MBit/s
  • 930K rows
  • 20KB/row of json

Took 66:40min - 4000 seconds.
During the migration the write IOPS were around 250, read at 50, cpu stayed at 60% throughout the run.

like image 23
Todor Minakov Avatar answered Oct 23 '22 20:10

Todor Minakov