Why HStore2/jsonb is the most important patch of PostgreSQL 9.4
databasesoup.com
databasesoup.com
Node has encouraged MongoDB usage because there were nice packages that made working with Mongo very easy. If Postgres supports JSON with powerful features then developers will make npm packages that support it and this will make Postgres very attractive.
While that makes it about 10 years younger than Postgres and MySQL, it's still not a flash in the pan.
And even if you don't like MongoDb or Node, JSON is clearly one of the most popular data formats - better support is surely a good thing.
But this is different because the postgres architecture is very much capable of great support here, and getting even better. Postgres has the best support for adding in new types, with amazing capabilities around indexing.
I'm not just talking about different kinds of BTrees, I mean real non-scalar indexing strategies like inverted indexes (used for full text, but also great for JSON), similarity matching indexes, unbalanced indexes, spatial indexes, etc.
The author merely wants to use this infrastructure as intended for the JSON use case. Easier said than done, of course, but no architectural compromises need to be made in the process of providing this support.
While I don't mind seeing some non relational additions like JSON, it shouldn't be detrimental to Postgres relational core.
It's not a pissing contest : if MongoDB is more popular than Postgres for non relational (NoSql) data so what ?
It's not like Postgres is a commercial product and need wider adoption to keep the parent company afloat.
The patchset in question is an improvement of hstore[0] (typed hstore, nested hstore) and unification of json and hstore (by using the binary hstore format for both). There is no more detriment to the relational core than when hstore or XML were originally added. Also, next-GIN[1] by the same people[2], not sure it's part of the patch mentioned.
[0] [PDF warning] http://www.sai.msu.su/~megera/postgres/talks/hstore-dublin-2...
[1] [PDF warning] http://www.sai.msu.su/~megera/postgres/talks/Next%20generati...
[2] Who previously contributed GiST and GIN, FTS, ltree or intarray
https://commitfest.postgresql.org/action/patch_view?id=1357 https://commitfest.postgresql.org/action/patch_view?id=1382
Yes, and it will. In fact the best post-relational features of PostgreSQL work best when used in a relational way.
> While I don't mind seeing some non relational additions like JSON, it shouldn't be detrimental to Postgres relational core.
As I usually tell people "Good object-relational design is usually good object-oriented design and good relational design, and that makes it really, really hard."
> It's not a pissing contest : if MongoDB is more popular than Postgres for non relational (NoSql) data so what ?
I would agree. The fact is that for the last 10 years, PostgreSQL has been the choice of open source rdbms's in business apps for the last 12 years and I don't see that changing.
> It's not like Postgres is a commercial product and need wider adoption to keep the parent company afloat.
Mindshare is important though.
I am working on a not-yet-released (needs test cases!) CPAN module called PGObject::Type::JSON.[1] This module would let you effectively grab JSON types from the db, serialize and deserialize on the db query so you don't have to worry about it.
The serialization and deserialization is cool, but the question is what you can do with it. With the json functions if they become more functional, we could use JSON as an input to stored procedures, allowing arbitrarily complex data types to be fed into or out of stored procedures easily without having to serialize in tuple/array format.
A single, cannonical, well supported format would be huge in that it would allow you to do things with the database with extraordinary ease that are not trivial to do today. For example, really good json support + composite types as tuple elements (including arrays of composite types) + really good indexing support should give you an ability to approximate the power (for at least some workloads) of full custom type development, without needing to go to C.
And like some of the comments said, PLEASE auto-partitionning!
"Here is a financial transaction. Please make sure it is balanced and post it."
This is not trivial to do right now. Top-notch JSON support would make it a breeze.
The JSON in 9.3 is almost good enough for this. It doesn't handle nested data structures to sql nested complex types properly, and so it won't quite get you there but otherwise agreed.
I.e. to make it work currently you have to slice and dice the JSON in some fun ways first. I find it less painful to just handle the complex type serialization/deserialization on the client side.
Same idea as ORMs... Making any CRUD operation is easy in SQL, why did we need ORMs? Yet, there is a fragment of the population who wouldn't use a database they couldn't talk to through an ORM. Today, there is a segment of programers that won't use a database if they can't PUT({"name": "Big Bird", "address": "123 Sesame street"}), because, you know, that's the modern way to do things.
Personally I prefer to tackle this from the other side with stored procedures and service locators so my application code is free of SQL (aside from the service locator), and all my SQL is in .sql files.....
What does it matter if it is JSON or not. In financial transactions you want:
* Maximum fault tolerance * Auditability * Security * Performance * Ability to roll it back with all the cleanly defined states in between * Ability to talk to legacy / standard systems
JSON-ifying the contents of the transaction is nice. But I wouldn't think that is the main pain point in the industry at the moment. It is really the behavior of the systems outside the transaction contents itself that matters.
It makes it easier to pass the complex data regarding a financial transaction into a stored procedure all at once. That's the non-trivial part today.
The "backend" for these types of applications are often relatively thin API wrappers around a database, with the bulk of application logic on the client-side.
Postgres' JSON improvements over the last couple of years have made it a pretty good choice already for these sorts of things, but the JSON indexing improving would make this a no-brainer.
Following fashion usually doesn't lead to good results.
http://blog.appfog.com/node-js-is-taking-over-the-enterprise...
And those a just the ones I have happened to hear about with major node.js projects.
If nothing else, it's a great exercise to make sure that postgres isn't missing out on a real, fundamental use case. Fashionable technologies don't always have something new to offer, but sometimes they help you see something from a new perspective.
[1] Postgres is very non-traditional in many respects, and I personally believe it's revolutionary; but many people perceive it as more traditional.
I don't know what you are basing that on, but it's the complete opposite of what I am seeing. Postgres is now the default open source database as far as I can see, especially for Rails. MongoDB enjoyed a brief hype-fuelled day in the sun but is now viewed as a specialised tool whose choice over a more general RDBMS would require considerable justification.
I suspect the question of whether its popularity is "exploding" or not depends on your definition of the word. I have certainly noticed a very marked uptick in the last few years. Not exploding perhaps, but certainly ballooning.
Well maybe Postgres and Mongo are replacing MySQL. I haven't seen Postgres being the default, but who knows, I mostly hang around with people who have been long term postgres users anyway.
The author appears to come from much more of a node.js angle and so probably what he sees is different. I'm probably underestimating the number of node.js projects so the author likely has a good point. Still, I'd raise an eyebrow pretty highly at anyone who considered MongoDB a solid default choice for a general purpose application. Most companies I know who opted for MongoDB regret it, for reasons that have been rehashed here any number of times.
Really ? I still see MySQL and MongoDB both being the two most deployed.
MongoDB, though - I do question that, however I have no figures and it again probably depends on the circles in which you move whether you see a lot of it or not. I don't move in node circles much, so I hardly see it at all.
Mea culpa. That said, in the startup-filled tech incubator in which I work, and in which rails is pretty dominant, postgres is king. Make of that what you will.
Postgres is the "default" database for django installations.
> MongoDB is replacing MySQL not Postgres.
That's part of the point, if user bases are switching databases, that's a chance for postgres.
> I would be interested to know what proportion of Postgres users use the JSON features, I suspect it is still small
For good reasons since it's still young (first introduced in 9.2) and fairly limited (9.3 did add operator and indexation as well as a bunch of functions). I'm in a postgres shop and we aren't quite ready yet to drop support for all postgres versions preceding 9.3 (to my dismay).
Is it? It is the recommended DB, between oh, MySQL, PostgreSQL, Oracle and Sqlite3
But I've yet to see an actual statistic on that.
With 3rd party plugins you can even use it on Microsoft SQL Server (though of course I don't recommend it unless it's a specific thing)
Hence "default". You can use any db you want, but if you follow the documentation or ask which one you ought use, Postgres will be suggested and recommended. Sounds like a default to me.
https://docs.djangoproject.com/en/dev/ref/databases/
I've only used Django with SQLite but I would be shocked if it was actively recommending a single database. It would imply that somehow Django doesn't work as well with the others.
So I think it's also South who's not as good in doing upgrades in MySQL as it is with PostgreSQL
https://wiki.postgresql.org/wiki/Transactional_DDL_in_Postgr...
According to the documentation DDL remains non-transactional in MySQL 5.5[0]
> The CREATE TABLE statement in InnoDB is processed as a single transaction. This means that a ROLLBACK from the user does not undo CREATE TABLE statements the user made during that transaction.
[0] http://dev.mysql.com/doc/refman/5.5/en/implicit-commit.html
FAQ: https://docs.djangoproject.com/en/dev/faq/install/#what-are-...
> you’ll also need a database engine. PostgreSQL is recommended, because we’re PostgreSQL fans
geoDjango (bundled): https://docs.djangoproject.com/en/dev/ref/contrib/gis/instal...
> PostGIS is recommended
the migration document also clearly notes that postgres has the best migration support, although it does not outright recommend it (probably because migration is generally an afterthought and production database has already been decided by then)
Not my experience. I have found that PostgreSQL has a remarkably stealthy popularity. I went to a conference a couple years ago and everyone knew PostgreSQL, and even there were more booths advertising Pg services than MySQL services.
Postgres is not popular if we talk enterprise world that has been buying Oracle. Oracle is an immense behemoth in that space with skilled salesmen, and they make lots of money.
I once asked an Oracle salesman what he thought of MySQL and PostgreSQL and he laughed, and basically said they are seen as joke by his customers. Maybe he was brainwashed sure, but I suspect that reflects (reflected? that was 2-4 years ago) the reality in that market.
Now with companies outside the enterprise (startups) and for internal projects, I feel Postgres has been very popular. MySQL effectively become unappealing after its trademark issues. Postgres gained a some of those users. It also gained disillusioned NoSQL people, some didn't RTFM, some were mislead, some didn't understand the problem well enough and so on.
I haven't been following the PG developers mailing list that closely recently and the article doesn't go into any details as to why it may be delayed.
From the link that @masklinn posted (Thanks, very interesting!) to a hstore presentation, it looks like the hstore side was developed by November last year, so I'm wondering why it wouldn't be ready for release by this September or whether its just the integration of hstore/JSON side of things that is the hold up.
For me, the new PG feature - although its an outside project - which I am most looking forward to in the 9.4 time frame is a newer JDBC driver for Postgres ( https://github.com/impossibl/pgjdbc-ng ).
That should completely short circuit the whole value proposition discussion of pg vs mongo.
You could run it either on the PG host, or on the same host as the apps wanting to talk to PG.
Waterline does support both MongoDB and PostgreSQL, though, so you could use it as part of a migration strategy: start with MongoDB, install Waterline backed by MongoDB, migrate your app to use Waterline rather than using MongoDB directly, replace MongoDB with PostgreSQL.
Go is also a new language and framework that is popular but it has a different feel, a better one. Python so far, has one of the largest and most pleasant community (given its size) I've seen.
Json/KV friendly features are welcome, but perhaps looking to impress Node.js and MongoDB users is just barking at the wrong tree.