2ndQuadrant is now part of EDB

Bringing together some of the world's top PostgreSQL experts.

2ndQuadrant | PostgreSQL
Mission Critical Databases
  • Contact us
  • EN
    • FR
    • IT
    • ES
    • DE
    • PT
  • Support & Services
  • Products
  • Downloads
    • Installers
      • Postgres Installer
      • 2UDA – Unified Data Analytics
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
  • Postgres Learning Center
    • Webinars
      • Upcoming Webinars
      • Webinar Library
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Blog
    • Training
      • Course Catalogue
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
    • Books
      • PostgreSQL 11 Administration Cookbook
      • PostgreSQL 10 Administration Cookbook
      • PostgreSQL High Availability Cookbook – 2nd Edition
      • PostgreSQL 9 Administration Cookbook – 3rd Edition
      • PostgreSQL Server Programming Cookbook – 2nd Edition
      • PostgreSQL 9 Cookbook – Chinese Edition
    • Videos
    • Events
    • PostgreSQL
      • PostgreSQL – History
      • Who uses PostgreSQL?
      • PostgreSQL FAQ
      • PostgreSQL vs MySQL
      • The Business Case for PostgreSQL
      • Security Information
      • Documentation
  • About Us
    • About 2ndQuadrant
    • 2ndQuadrant’s Passion for PostgreSQL
    • News
    • Careers
    • Team Profile
  • Blog
  • Menu Menu
You are here: Home1 / Blog2 / Giuseppe's PlanetPostgreSQL3 / NoSQL with PostgreSQL 9.4 and JSONB
2ndQuadrant Press

NoSQL with PostgreSQL 9.4 and JSONB

February 23, 2015/1 Comment/in Giuseppe's PlanetPostgreSQL /by 2ndQuadrant Press

articolo-json-giuseppe

The introduction of the JSONB data type in PostgreSQL, definitely makes the “NoSQL” side of this relational DBMS come out: this introduction meets the requirements of all those who prefer a data structure in a “key-value” array, dictionary style (widely used in the field of development) and, at the same time, ensures all the advantages of a relational database.

PostgreSQL 9.2 already provided for the use of JSON type, maintening the compatibility of JSON data directly in a database. However, it was a text type data with the ability to validate JSON syntax. With this new type of JSONB data, information is stored in a dedicated binary format. So it is possible to benefit from specific algorithms which improve access performances and optimise storage on disk, which offer:

  • advanced access and comparison operators: thanks to the specialised structure, JSONB has allowed the implementation of new operators that, in addition to offering more flexibility, allow the user to harness the full power of hash, btree, GIST and GIN indexes;
  • reduced dimensions on disk: the space required to store documents of a complex structure with the JSONB data is smaller than disk requirements for the JSON format;
  • internal organisation as a dictionary with a unique key: this means that access is extremely fast, but the key order of entry within the JSONB structure is not preserved. Furthermore, in the presence of duplicated keys, only the last entered value is maintained, unlike to what happened with JSON data:

    $ SELECT '{"a":1, "b":2}'::JSONB = '{"b":2, "a":1}'::JSONB
     ?column?
     --------
      t
     (1 row)
    
    $ SELECT '{"a":"abc", "d":"def","z":[1,2,3],"d":"overwritten"}'::JSON
                  JSON
      ----------------------------------------------
      {"a":"abc", "d":"def","z":[1,2,3],"d":"overwritten"}
      (1 row)
    
    $ SELECT '{"a":"abc", "d":"def","z":[1,2,3],"d":"overwritten"}'::JSONB
                  JSON
      ----------------------------------------------
      {"a":"abc", "d":"overwritten","z":[1,2,3]}
      (1 row)

It is anyway necessary to point out that JSONB data is compatible with all functions introduced for the JSON data.

The effects of this possibility of indexing the JSONB type is translated into a better availability of data to be read, thus allowing an efficient access to the whole content of a JSONB field.

This makes it possible to efficiently use PostgreSQL in order to analyse data which does not have a predefined scheme, by moving it closer to the “NoSQL” world. In this regard, community member Thom Brown conducted some tests showing how an increase in reading performances (and a more reduced space occupied by indexes) was found, as compared to a JSON field, thus reaching reading performances even higher than those of typically NoSQL DBMS, such as MongoDB.

Conclusions

The introduction of +JSONB+ type definitely moves PostgreSQL closer to developers who normally use data in a +JSON+ format. An example is web developers who widely use JavaScript and have possibly already started working with PostgreSQL using the +JSON+ type for storing data. By evolving to +JSONB+, they will be able to use all the power of the PostgreSQL engine to develop that data easily and efficiently.

Tags: 9.4, array, btree, database, dbms, dictionary, GIN, GIST, hash, javascript, JSON, JSONB, key-value, mongodb, NOSQL, object, postgres 9.4, PostgreSQL, PostgreSQL 9.4, unstructured data
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
1 reply

Trackbacks & Pingbacks

  1. JSONB type performance in PostgreSQL 9.4 | 2ndQuadrant says:
    March 3, 2015 at 9:54 am

    […] NoSQL with PostgreSQL 9.4 and JSONB → […]

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Get in touch with us!

Recent Posts

  • Random Data December 3, 2020
  • Webinar: COMMIT Without Fear – The Beauty of CAMO [Follow Up] November 13, 2020
  • Full-text search since PostgreSQL 8.3 November 5, 2020
  • Random numbers November 3, 2020
  • Webinar: Best Practices for Bulk Data Loading in PostgreSQL [Follow Up] November 2, 2020

Featured External Blogs

Tomas Vondra's Blog

Our Bloggers

  • Simon Riggs
  • Alvaro Herrera
  • Andrew Dunstan
  • Craig Ringer
  • Francesco Canovai
  • Gabriele Bartolini
  • Giulio Calacoci
  • Ian Barwick
  • Marco Nenciarini
  • Mark Wong
  • Pavan Deolasee
  • Petr Jelinek
  • Shaun Thomas
  • Tomas Vondra
  • Umair Shahid

PostgreSQL Cloud

2QLovesPG 2UDA 9.6 backup Barman BDR Business Continuity community conference database DBA development devops disaster recovery greenplum Hot Standby JSON JSONB logical replication monitoring OmniDB open source Orange performance PG12 pgbarman pglogical PG Phriday postgres Postgres-BDR postgres-xl PostgreSQL PostgreSQL 9.6 PostgreSQL10 PostgreSQL11 PostgreSQL 11 PostgreSQL 11 New Features postgresql repmgr Recovery replication security sql wal webinar webinars

Support & Services

24/7 Production Support

Developer Support

Remote DBA for PostgreSQL

PostgreSQL Database Monitoring

PostgreSQL Health Check

PostgreSQL Performance Tuning

Database Security Audit

Upgrade PostgreSQL

PostgreSQL Migration Assessment

Migrate from Oracle to PostgreSQL

Products

HA Postgres Clusters

Postgres-BDR®

2ndQPostgres

pglogical

repmgr

Barman

Postgres Cloud Manager

SQL Firewall

Postgres-XL

OmniDB

Postgres Installer

2UDA

Postgres Learning Center

Introducing Postgres

Blog

Webinars

Books

Videos

Training

Case Studies

Events

About Us

About 2ndQuadrant

What does 2ndQuadrant Mean?

News

Careers 

Team Profile

© 2ndQuadrant Ltd. All rights reserved. | Privacy Policy
  • Twitter
  • LinkedIn
  • Facebook
  • Youtube
  • Mail
Incremental backup with Barman 1.4.0 JSONB type performance in PostgreSQL 9.4
Scroll to top
×