Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5WUW-0007PI-47 for pgsql-general@arkaria.postgresql.org; Tue, 11 Aug 2020 15:47:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5WUU-0004qb-BN for pgsql-general@arkaria.postgresql.org; Tue, 11 Aug 2020 15:47:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5WUU-0004qU-2v for pgsql-general@lists.postgresql.org; Tue, 11 Aug 2020 15:47:06 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k5WUK-00079c-KP for pgsql-general@postgresql.org; Tue, 11 Aug 2020 15:47:03 +0000 Received: by mail-ej1-x644.google.com with SMTP id g19so13577913ejc.9 for ; Tue, 11 Aug 2020 08:46:56 -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=WKIwvMOgk+GJEwGKYiAmj83BSI2BeMBOqtf2llGwJ54=; b=BickaTj8KtxAQCSgmpBoOsr7IFnWasZGTOJReJOm5/vTlRlMkwgCEkbumlMAcT511q lLkPXwIbtk+iyYj837x6lEaolz3bHteGjHF0MZMhJGqQsfOYa/fQezp5nSsID4kl0tRN fzQLsUA782ZoO7QnNaX/GHGLCkwX7aA103f4D7Iy+hXlVZ3vti0Py0POL1gmZpcyJS8O 7q0WdsLY2C4tHgB5hGiZACH+k0ilEY5I6LWCq/n8LpUM+SLpxShmx03QOHI7UBX6eW7W aJr3BPdHn5dsrlS0lh/P85Y2uWs/oGbx7bBt8yrP4reuvmQKJAHSVlYRuExyMjWPZVwp a7nA== 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=WKIwvMOgk+GJEwGKYiAmj83BSI2BeMBOqtf2llGwJ54=; b=HUADxHmKCGCiUbhR5KmhgLidM+Jew+qS2bBQgkL0rq1c5RMSt+zWj00MMKNcggN3B6 2Pt/RjdxnKBd8A/twn57nUWImuMU5eKDE9FlTJ/TeuI850I5TZkogpW23CYTFwiSWJIw Q6u7qLy/6pJkTWWfjhVtfuXzXqklLc9PBWd/Xl/Kw+yQGx0FZD2kBvYlKdDeOyMR9sBD QHZttaKjrwWrZXwqtIWpiy1dcprGTSfFF+czwVN62SeBI4qwHaaaqh1SAssLxU6tleVS y/Ty7OIKGt4n0VJGcR/6iSZ6x+3+Awavmcf5LVTjzhN3Lrf26akf1axhlqQ5zJtS/Zae wmdg== X-Gm-Message-State: AOAM533fX1B2EcAnVekls3NVsdNfgud0hPHP3CV70Ungqkk+q1lJ/Kkb q3sDBnajAMf34m2M0309b3U= X-Google-Smtp-Source: ABdhPJzh7SwQ04c48b3F+veALGI5r+AK/SAOVei6Q3n79KVE2WLxS/YL/zrcdzqsfPER/4aWIccTTg== X-Received: by 2002:a17:906:3890:: with SMTP id q16mr26252054ejd.107.1597160815732; Tue, 11 Aug 2020 08:46:55 -0700 (PDT) Received: from [192.168.1.8] (241-57-239-77.dyn.cable.fcom.ch. [77.239.57.241]) by smtp.gmail.com with ESMTPSA id gh24sm15503716ejb.45.2020.08.11.08.46.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2020 08:46:54 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Subject: Re: How is PG replication typically used to create a High Availability (HA) config ? From: =?utf-8?Q?Paul_F=C3=B6rster?= In-Reply-To: Date: Tue, 11 Aug 2020 17:47:01 +0200 Cc: Postgres General Content-Transfer-Encoding: quoted-printable Message-Id: References: To: David Gauthier X-Mailer: Apple Mail (2.3608.120.23.2.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi David, > On 11. Aug, 2020, at 17:12, David Gauthier = wrote: >=20 > Hi: >=20 > Our IT dept has created what they call a High Availability DB for our = PG DB (9.6.7 on linux). If the primary fails, they promise to promote = the backup to be the new primary but leave it at that. But from the = perspective of the app, I'm left with.... > 1) detecting an SQL error is a DB connectivity problem. > 2) Attempt to reconnect. If fails, try connecting to the backup = server (assume it's the new primary ?) > 3) If that works, then test to see if it is indeed a primary (try a = write statement) ? > 4) Somehow remember that the backup server is the one to connect to as = the primary for future connections. > 5) When the original primary server is fixed and brought back on-line, = and they promote it to being the new primary, then I guess my write = statements will fail because I'm still connecting to the backup. So go = figure that out and reset a pointer of sorts to the new primary ? >=20 > Seems like a lot of work for an app and that it should be more = seamless. But maybe I'm wrong. >=20 > I was hoping for something like a server alias that the IT team = toggles as needed between the servers so that I always know what to = connect to. The best solution would be something completely seamless... = my app isn't even aware that the primary went down, the backup was = promoted, and that I'm actually running on a different server. Is = something like that possible ? >=20 > Thanks for any replies ! If you're a developer, you can take a look at: https://www.postgresql.org/docs/current/libpq.html If your application uses libpq, then you can have it connect to the = primary database, no matter on what host the primary and the replica = currently is. Look at: https://jdbc.postgresql.org/documentation/head/connect.html You can especially do something like: = jdbc:postgresql://host-a:5432,host-b:5433/postgres?targetServerType=3Dmast= er You can always download the current driver from: https://jdbc.postgresql.org Does that help? Cheers, Paul=