by moe · 11y ago · 0 comments
Why can't we just type "enslave 10.0.0.2" into psql and have the computer do the hard work? The machinery is "almost there" for a half a decade now. Who do we have to bribe (wink wink, nudge) to bring the UX into a state where crutches like pg_rewind are not needed?
PostgreSQL generally builds things from the bottom up -- first working really hard to get the fundamental infrastructure right, and then the utility starts falling into place.
This has a few advantages:
* The fundamental infrastructure tends to be more general, so many different functional improvements come out quickly after the infrastructure is in place.
* It forces everyone involved to think through the edge cases first, leading to a more robust feature and a better-tested feature.
* When things go wrong, all of the parts make more sense individually, so it's easier to understand what happened and fix it.
* Eventually, the usability issues are addressed in a way that's not dependent on a lot of black magic.
Anecdotally, when things go wrong in $MAGICALLY_REPLICATING_DB, they tend to go very wrong, very fast. I am skeptical by nature, so I generally assume that $MAGICALLY_REPLICATING_DB glosses over a lot of the finer points, which don't get exercised in a normal testing environment. I haven't presented any facts here, so you may disagree.
A lot of people share my skepticism, and are willing to put up with a few rough edges in the usability as long as the pieces make sense and they feel they can understand and trust them. I was at a presentation by Instagram, and replication was one of the primary reasons they went with postgres. They used a tiny engineering team (one and a half engineers working on the database) to scale to tens of millions of active users (also using sharding; another thing that is harder to use but easier to understand in postgres).
And it's really not that hard. MVPRC (Minimum Viable PostgreSQL Replication Configuration):
Master:
postgresql.conf:
wal_level = 'hot_standby'
max_wal_senders = N
pg_hba.conf:
host replication all A.B.C.D/E md5
Slave:
postgresql.conf:
hot_standby = 'on'
recovery.conf
standby_mode = 'on'
primary_conninfo = 'host=W port=X user=Y password=Z'
Literally six lines of "directive = value". (Well, five plus the HBA rule.)Then you use pg_basebackup, and start the slave.
EDIT: Decided to be specific instead of handwavy.
Which is six lines too many for what is inherently a runtime configuration that shouldn't be mentioned in any config file at all.
Then you use pg_basebackup, and start the slave.
I take it you don't care for failover and monitoring then?
Otherwise you would have mentioned either repmgr and pgpool here, or your conglomerate of rather complex homegrown scripts to mimic their functionality.
Replication isn't "inherently" anything. Making it a runtime thing is one way of doing it. Just because it's your preferred way (or — as often seems to be the case among people who share your opinion about how postgres does it — just how they were first exposed to it) doesn't make any of the myriad other, perfectly viable ways of doing it wrong.
As for my "conglomerate of homegrown scripts", I keep my db configs versioned in git, and use symlinks from $PGDATA into a role- and environment-specific (e.g., testing-master or production-slave or whatever) subdirectory in a clone of that repo. Puppet clones the repo on spinning up a new machine, and I repoint the symlinks as necessary. You know:
$ ln -sf /path/to/repo/environment/role/*.conf $PGDATA/
Complex, huh?Doesnt MySQL Cluster do this pretty well?
Which relates to a master/slave cluster as in how?
no other open source RDBMS out there manages those things either
Rethinkdb, Redis, Riak, ElasticSearch all do.
(them not being relational is irrelevant to replication)
Making it a runtime thing is one way of doing it.
It's the only way of doing it for modern, dynamic application layouts (the whole "cloud" thing). The stereotypical static database cluster, carefully configured by a graybeard once and then never touched again, it still exists. But it's rapidly losing ground.
Puppet clones the repo on spinning up a new machine, and I repoint the symlinks as necessary.
So how do you monitor e.g. the replication lag?
Having tried that out, I didn't find it particular user friendly compared to the various fancy NoSQL database where it's just something like... database-server --connect the_master:12324 -- and you've got your cluster even with automatic replication of data depending on your sharding rules.
I suppose that ACID-SQL makes it harder to set this up reliably.
Is there one of the commercial things like EnterpriseDB that fixes that? Effortless, reliably clustering with a nice status that says: slave2 is 95% sync'ed with master1 ETA 2 hours.
I know it is functionally immaterial, but boy howdy do I ever wish we'd chosen a better convention for how to refer to the relationship between these system components.
There's nothing wrong with Master/slave. We also read man pages, shove male plugs into female ports, fork and kill children, and use dozens of other odd words to describe perfectly harmless things.
There's nothing essential about master/slave so why not just switch to primary/replica?
Neither Master nor Slave is a derogatory word. And using the concept of slavery to describe a relationship between inanimate objects in a technical context is not an endorsement of such practices between humans.
And to the OP, replication is a complex process fraught with security risks. Take about 10 minutes thinking about just roles and authentication in the context of your proposed syntax and what you would need to set up ahead of time to make it work.
The current method of starting with a pg_basebackup on the replica is nearly as simple. Even if it does require that you do some minor configuration on the master. It's not nearly open heart surgery.
Nothing except a shared secret or keypair. Other databases (rethinkdb, redis, riak etc.) show how it's done.
Primary/Replica?