Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hujvk-00024W-6K for pgsql-general@arkaria.postgresql.org; Mon, 05 Aug 2019 20:50:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hujvj-0004gz-0Y for pgsql-general@arkaria.postgresql.org; Mon, 05 Aug 2019 20:50:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hujvi-0004g9-Lj for pgsql-general@lists.postgresql.org; Mon, 05 Aug 2019 20:50:06 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hujvf-00025V-NC for pgsql-general@lists.postgresql.org; Mon, 05 Aug 2019 20:50:06 +0000 Received: by mail-ed1-x543.google.com with SMTP id k21so80250839edq.3 for ; Mon, 05 Aug 2019 13:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=NJYOJhjKnrDMY1/5m0l+LId1yJtbbjUyFBwakmfaAAo=; b=c2GMA/tBGjHV18DQMnjqnezkksqyTtQfT31ThEUoGJ3D0fn/LF+nJ3jI8AE18KobZd YxVqtJILgaE/Ty7sJeTgTk4SGzsXb2HI0nRV0JDEudnvEIGIAr+0vj0McJ9fWNsEKr7h Qy8EqIw0zK/SVg87LdXdnPvPc9CheNt2TpF3imjhHshwu+B4ZecqODFNSEk65xz1VMQT v97TIC5DyIc04fj50N6x3SrNB0g8kZgCCIFO94vcDsZgWs0TwDIynJX5rn4K5GFJPzk/ JGwn+TE8VJtPZpQToSho6SizUJ3itKxg8GXu1U+qQnlkPrc77ziK08mK6R/dt/LqVLlA sLsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=NJYOJhjKnrDMY1/5m0l+LId1yJtbbjUyFBwakmfaAAo=; b=X88+1yyoCb7CgBYj/4mSWn+HsdI5a0auvmA2/IQlvGy9zayjRRZZlLDSibCePrJDji czAvFXIKwGyxbmX7v6MpTxwO9xFcdjXEt3+8pWWL0QXZjN6uT3k5Fd/DC7BwX6FMM8iZ I/QAwf93s3xx5GktrOk/LHH4zGK3jl+oRSdvB0AqV0PxOsx8NdYKlfN/AEg0r3EC02lb JMr7UQC5MEoMqyX2g5vWwrTek2UaZrxIKcGIq4EFefNQli2qek4IYmUbpJgeXSKfI/ni dgVoP9hqISsmyqeJR7HJa4RcgNqipmpBdDTFU0mg+7AB/tDPgnyypKRWCU5049K4GNy0 T5Ww== X-Gm-Message-State: APjAAAUmxrtIjbOoYSTbTlqFIN/3ioctrQyaxAANjmZ4xvFqsFz4C+p0 2H2iMnBJYnOpLsCB4lIEzRM= X-Google-Smtp-Source: APXvYqzPe66knBnSzeoCMxgifp+gcFVEvtJGPY5ShI3ujobEQCdaO5ekYqTB10z9m92bA/k9xiwy4A== X-Received: by 2002:a17:906:5042:: with SMTP id e2mr19240ejk.220.1565038201752; Mon, 05 Aug 2019 13:50:01 -0700 (PDT) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id b30sm20507187ede.88.2019.08.05.13.50.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Aug 2019 13:50:01 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: adding more space to the existing server From: Alban Hertroys In-Reply-To: Date: Mon, 5 Aug 2019 22:50:00 +0200 Cc: Adrian Klaver , "pgsql-general@lists.postgresql.org" , pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: <3D8C27AF-E76F-4B76-9D6D-6E400AA74726@gmail.com> References: <13358DF7-5700-44A2-A86B-2A3721AA9650@gmail.com> To: Julie Nishimura X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 5 Aug 2019, at 17:27, Julie Nishimura = wrote: >=20 > Thanks for your reply Alban. Currently we only have A->B replication. = Is adding B->C replication difficult? I remember in the past I tried to = seed pg_basebackup from hot standby, and it was erroring out after = awhile, so needed to switch to run from master. I=E2=80=99ve never used multi-level replication (or cascading = replication, as it=E2=80=99s called in the PG docs). I expect that replication slots (w/ streaming replication) would be = resilient to streaming to multiple levels, provided that you have the = disk space left to keep the logs that your farthest-behind replica is = at, but I do not know that. I=E2=80=99m pretty sure that=E2=80=99s being = done though and not just theoretically possible. The basic problem you have is a bit like Towers of Hanoi. The details of = setting up each replica may be a little complicated, but if you look at = it from a high-level design phase, you=E2=80=99re just shuffling around = clusters. The details come later, when you=E2=80=99re actually designing = how to apply those replicas/clusters. One of the main problems is that creating a new replica takes a lot of = time, you want to minimise the total time that takes. Apparently, you = have neither C nor D ready yet, so you need to create two replicas - = being able to do those in parallel instead of sequentially would save = you time. The other problem is that, to be on the safe side, you want to have a = full replica of A at any point in time. If you disconnect B from A = before either C or D is complete, you run a risk: If A fails, you = don=E2=80=99t have the data that accumulated while B was =E2=80=98offline=E2= =80=99. So that=E2=80=99s not the best scenario. That is why I think your initial set of replicas should look like: A =E2=80=94 B =E2=80=94 C \ D IIRC, streaming replication uses pg_basebackup to create the initial = replica and then it streams what=E2=80=99s needed to catch up. With = replication slots, the master knows what the slaves still need, so it = won=E2=80=99t clean up too early. Apparently, the slave (B) knows that = it needs to retain data for C as well. It looks perfectly safe on paper, = except for the replication lag between A =E2=80=94 B. You can, according to the docs, cascade replicas from each other and = that even allows replication (among the slaves) to go on after the = master gets disconnected - quite what you need for the B =E2=80=94 C = chain, I would think. Take a look at: = https://www.postgresql.org/docs/11/warm-standby.html#STREAMING-REPLICATION= And note the sections on Replication Slots and on Cascading Replication. The replication lag between A =E2=80=94 B can be solved by pausing the = clients connecting to A (half of them need to be changed to B anyway) = while B is catching up on its lag. You probably have at least that much = down-time to change the connections anyway. Regards, Alban. > From: Alban Hertroys > Sent: Monday, August 5, 2019 5:01 AM > To: Julie Nishimura > Cc: Adrian Klaver ; = pgsql-general@lists.postgresql.org ; = pgsql-general > Subject: Re: adding more space to the existing server > =20 >=20 >> On 5 Aug 2019, at 0:39, Julie Nishimura = wrote: >>=20 >> Alban, thank you for your reply. Your suggestion makes sense, and I = will be talking to our engineers about it. Currently we need to = understand: >>=20 >> a) How do we break A -> B replication such that both can become = independent primaries >=20 > That is pretty much like normal failover from A to B, except that you = don=E2=80=99t reverse replication. >=20 > You will need to stop your clients from sending data for a bit (if = it=E2=80=99s continuous data, having a buffer in between is a big help - = at our company we=E2=80=99re looking into Apache Kafka for that), so = that you can switch half of them to connect to B instead of A. >=20 > Next, you promote B to master. I used the docs for that last time, and = they were pretty clear on the subject. >=20 >=20 >> b) How do we reassign C from B->C replication to A->C = replication >=20 > I don=E2=80=99t think you need to. If you indeed already have A->B->C, = after promoting B to master, you end up with B->C, which is alright. > You just need to add A->D for the other set. >=20 >> c) Thoughts on why this isn=E2=80=99t a good plan >=20 > That depends on your clients and how you decide which database in the = current cluster they connect to. If you connect specific clients to = specific databases, then all you need to do is to configure half your = clients to connect to B instead. >=20 > Another option is to put a virtual database layer in front, such that = both clusters still look like a single database to the outside world. We = have some experience with Dremio for similar purposes (although for = read-only reporting). Mind that the community edition doesn=E2=80=99t do = authorization. >=20 >> Current:=20 >> A replicates to B >> all requests go to A >>=20 >> Soon:=20 >> A replicates to B -> cascading to C and D >>=20 >> Transition:=20 >> break A replication to B such that both can become primary > Correct. >> stop B replication to C then setup A to replicate to C > I would change this in: > setup A to replicate to D >>=20 >> End state: >> A replicates to C >> B replicates to D >>=20 > End state: > A replicates to D > B replicates to C >>=20 >> we remove some of the dbs from A and B, then reassign the traffic = based on db selections >>=20 >> I hope it all makes sense... >>=20 >> Thank you > It does to me. Now would be a good time for people to chime in if they = don't agree ;) >=20 >>=20 >> From: Alban Hertroys >> Sent: Saturday, August 3, 2019 3:15 AM >> To: Julie Nishimura >> Cc: Adrian Klaver ; = pgsql-general@lists.postgresql.org ; = pgsql-general >> Subject: Re: adding more space to the existing server >> =20 >>=20 >> > On 2 Aug 2019, at 21:45, Julie Nishimura = wrote: >>=20 >> > 1) We use streaming replication, and due to hardware limitation, we = cannot add more drives to the existing host. That is why we thought by = breaking the existing streaming replication (from a->b), instead of = currently identical standby (b), we can introduce twice larger host, = then start the replication to the newly larger host, and when it is = caught up, break it again. Then break rep again, make modification to = 'a" host, making it larger, then replicate b->a. After it is caught up, = break the rep again, switch master->standby (if necessary). >>=20 >> Let=E2=80=99s be clear, I=E2=80=99m in no way an expert on = replication. In fact, I=E2=80=99ve only done (streaming) replication = once and I managed to mess that up in a minor way (disabled the wrong = service during failover, so data still went to the database I was = attempting to replace for, like, 15 minutes). >>=20 >> > 2) I am not sure about the time, but it is understood it is = required 2 full replication cycles, and might be up to 2 weeks with no = standby situation >>=20 >> No standby situation? Murphy is probably just waiting for that to = strike=E2=80=A6 >> I recall a fairly recent story on the FreeBSD ML about someone on = Malta doing a migration of a couple dozen terabytes from her main server = (because of some failing disks in her RAID set) using her backup server = to move data around (with backups removed to make room), when, due to an = accident outside the building, an aerial 10KV power line hit another = power line in the ground, causing a fire in one UPS and frying the other = one. Losing power at that point meant that the file systems (ZFS) on = both servers ended up in an unrecoverable state with no backups. It = didn=E2=80=99t help that the UPS=E2=80=99s were at the bottom of the = rack, with the heat and smoke going up into the servers. What are the = chances, right? (And then it turned out that it is really hard to try to = recover data from a ZFS file system in such a state, which is what her = actual inquiry was about) >>=20 >> I would definitely prefer to add a 3rd machine into the mix, even if = it were just a temporary machine - a rental perhaps? >>=20 >> =46rom there, I=E2=80=99m certain Adrian knows more about replication = than I do. I=E2=80=99d go with the approach he suggested. >>=20 >> > 4) by pg_basebackup and restore >> >=20 >> > As of now, we are thinking about possibly other solutions, as of = splitting existing 37 databases on the cluster into 2 hosts with their = own standbys. This solution requires breaking up existing replication as = well. Can you please point me to some document which lists all steps = describing breaking up the existing replication properly? we are using = 9.6 postgres >>=20 >> I=E2=80=99m going to assume that you will have data coming in while = this split is taking place and that you therefore cannot offline the = entire set of databases for as long as this takes. If not, that would = probably allow for a simpler (faster) scenario. >>=20 >> I think the easiest for this scenario would be to add two more = machines (c and d) and replicate them off the current setup. You want = that to happen as parallel as possible, so perhaps replicate c off a and = d off b. >>=20 >> If you aren=E2=80=99t already using =E2=80=9Creplication slots=E2=80=9D= , I found that to make things both easier to understand and more = reliable. You can query their status, for one thing. >>=20 >> Those replicas will take extra time of course (about double) because = you=E2=80=99re replicating twice what you need, but I don=E2=80=99t = think you can replicate parts of a cluster with your setup unless you go = for a different replication approach (I think per database replication = requires statement level replication?). >>=20 >> After that, decouple both sets into: >> a =E2=80=94> b (your current machine) >> c =E2=80=94> d (the new ones) >>=20 >> (Although any order should be fine, really, as long as they have = caught up.) >>=20 >> At that point I would probably (temporarily) pause replication in at = least one set and create a backup of that. >>=20 >> This is the point to start removing superfluous databases from a and = c (so that a+c make up the complete set again). >> After verifying that no databases are missing, unpause replication. >>=20 >> If instead you find that you accidentally removed a database from = both a and c, you still have replicas to recover it from. And the = backups, of course, but that will not contain the data that came in = after replication was paused. >>=20 >> I do hope the remaining 3% disk space is enough to cover all that, = though... >>=20 >> Regards, >>=20 >> Alban Hertroys >> -- >> If you can't see the forest for the trees, >> cut the trees and you'll find there is no forest. >=20 > Alban Hertroys > -- > There is always an exception to always. Alban Hertroys -- There is always an exception to always.