97 points · by Vorcin84 · 10y ago · 47 comments
To be clear, what I want is: - The ability to deploy a cluster of say, 5 replicated PostgreSQL instances - All write transactions go to a single leader, which replicates them to the other instances - Reads can go to any instance - If a leader crashes the cluster will elect a new one without human intervention, and no committed transactions will be lost.
I've always been unclear on how to do this with Postgres.
I've worked mostly with MariaDB Galera Cluster which is pretty effortless to setup, but for PostgreSQL there doesn't seem to be any clear direction on how to do the same things.
There are plenty of other replication solutions available for Postgres, indeed.
The significance is one of performance and convenience: before, you would have had to construct a new jsonb object with only the field(s) you wanted modified changed. (In fact it is possible to define these new operators in terms of such; I have done so.) Now you can just use these handy built-in functions, which presumably perform better than the manual method as well.
If you do:
update aTable
set loginInfo = loginInfo - 'lastLogin'
where 'loginInfo' is a jsonb column, you, the programmer, need not write out the parts of the data to keep. PostgreSQL still sees this as 'read column, evaluate expression, write result', so it will read and write the entire jsonb value.When you do need to update JSONB columns this is a big improvement. You still should consider the size of your JSONB columns and the number & frequency of updates to those rows.
Document storage in Postgres is a best-of-both-worlds approach (can store documents w/ ACID), with advantages of MongoDB and fewer downsides. But it's still relatively new functionality. (I've seen use cases of document storage for logging in-database and other quick-write/read-rarely data that would be a pain to normalize with consistent schema, which seems compelling)
SQL has never ever been meant for "editing documents", doing so is certainly not considered "basic functionality" for anyone whose use case is best served by a RDBMS, and you'll likely be displeased by the performance of such in Postgres (or any other RDBMS) if that is something you consider "basic functionality".
(FWIW: what I've found to be the typical use case of JSON-in-SQL (or XML-in-SQL) is that of storing opaque JSON or XML blobs generated by some external service, which could perhaps benefit from indexed lookups within this data. If you're designing your main SQL database around JSON you're probably doing something wrong.)
* If I wanted to make Postgres listen on non-localhost, modify listen_addresses in postgresql.conf.
* Add database access controls as required in pg_hba.conf. The comments in the file are illuminating, but one can examine [0] for more information. [1]
* Create a database with appropriate permissions, along with a user. [2]
* Start Postgres.
I remember having to do the equivalent of all of those things every time I had to install MySQL. :)
What -exactly- did you successfully do, what -exactly- did you fail to do? Divulging that information will help guide assistance efforts. :)
[0] http://www.postgresql.org/docs/9.4/static/auth-pg-hba-conf.h...
[1] For example, the following line would allow password-based access from IPv4 localhost by the user "user" to the database "database":
host database user 127.0.0.1/32 md5
[2] http://www.postgresql.org/docs/9.4/static/sql-createdatabase... for CREATE DATABASE syntax (or you can use createdb http://www.postgresql.org/docs/9.4/static/app-createdb.html ) http://www.postgresql.org/docs/9.4/static/sql-createrole.htm... for CREATE ROLE syntax (or you can use http://www.postgresql.org/docs/9.4/static/app-createuser.htm... ) http://www.postgresql.org/docs/9.4/static/sql-grant.html for GRANT syntax.It's also in most distro and bsd repos.
For the benefits of PostgreSQL over MySQL it is definitely worth learning.
Other things are just confusing to newcomers (eg. different meanings of the term "database" between MySQL and Postgres, or understanding schemas and search_path).
I find that to be the easiest way to get up and running with it.