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 1k5bSm-0003dJ-UI for pgsql-general@arkaria.postgresql.org; Tue, 11 Aug 2020 21:05:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k5bSk-0006tF-Ln for pgsql-general@arkaria.postgresql.org; Tue, 11 Aug 2020 21:05:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k5bSk-0006t8-Bk for pgsql-general@lists.postgresql.org; Tue, 11 Aug 2020 21:05:38 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k5bSh-0002Co-EI for pgsql-general@lists.postgresql.org; Tue, 11 Aug 2020 21:05:37 +0000 Received: by mail-oi1-x229.google.com with SMTP id v13so13538475oiv.13 for ; Tue, 11 Aug 2020 14:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=0bDd+ktHt7Sv2HmXaHC1T03w1JwCF4mkD9YZhc7coQA=; b=TwSO8GJt/unrh1dfl23X0886AWecX3T7XYWkrKW/SR/jM271aMQF5R+GHMiCGjkI0L 42VuHSwtlfaDI7HUqXyfH0cIYoeQ8A96JF/5ZCXyYym7iJKMoAgSzbs2s/EK+4LThhhm eW6TJ6y6/xs4hdDdsXFjlUlm49kDpDpqJsbeWKFBpgta9px7o5iVSTN3G3tpFdkY71YJ tgBsXEHMh8BOvUqgqDN9yNmD7lxYoiWxZ2S53ATY+s0kl8e5TGyOMXuunldLx/VVyoFT 0CF8ZqhiGs8WpkLi/XOlVrcS4wJ12GcbX1eVGvAvWBlzSzEklIz76DvigwEarviIE07S ZoZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=0bDd+ktHt7Sv2HmXaHC1T03w1JwCF4mkD9YZhc7coQA=; b=or1eeUarCdHY4oEz4nHzBgg0qTMxuxd7WBWAWmm+hTyfjxFLEJhuT3yDciesh4rhjA CMANMZPT8BKomBdFu1M1yTtm4AtbWBVcm2RbKFjv9WK2Zp1u7hIYSbRyxZjSpRY485MG BvtJTbjY0WmpTQCQTjc+ZW1GsTCUXnptjhMytPlK2n4oCqsO13cAFeBbT+H47PTXCKor 6LWDrtHJPnrtrHHqz5JYn0Go9NCjRA9KHdL5GygYikIoRvZZUeFH2Ontgvj5IAIy9QVX /6ZLk+NT9zSmz6iIKa5vQa8qmqDUyfy8hcPOJm2+6b6XjcH/Fd26rV66GWXGX1zdSF5J k+1w== X-Gm-Message-State: AOAM532KEUdAhtM1vB2t8CFE8iD7COxOfNpcC9wNnSzUEQsZ3d/t6aQZ GbvHe290khm95VUPdaAR2SJMxcIGlbo= X-Google-Smtp-Source: ABdhPJyV0qMg9805oLI0IeBImfiUtbByhtVz8eo+innaHk+jsUaXs75rBdnz/nTHIdTDzA8UWGeJsQ== X-Received: by 2002:aca:41d5:: with SMTP id o204mr4976805oia.35.1597179934200; Tue, 11 Aug 2020 14:05:34 -0700 (PDT) Received: from ?IPv6:2601:681:5500:dde0:a5e0:54fc:2206:41b5? ([2601:681:5500:dde0:a5e0:54fc:2206:41b5]) by smtp.gmail.com with ESMTPSA id r15sm4560233oor.35.2020.08.11.14.05.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Aug 2020 14:05:33 -0700 (PDT) Subject: Re: How is PG replication typically used to create a High Availability (HA) config ? To: pgsql-general@lists.postgresql.org References: From: Rob Sargent Message-ID: Date: Tue, 11 Aug 2020 15:05:32 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 8/11/20 2:57 PM, David Gauthier wrote: > Thanks for the response Paul :-) > > Our code is actually perl which uses DBI which has functions to ping a > DB on a specific server and connect to it. > But my question was more along the lines  of whether or not the onus to > do this sort of thing typically lies with the app or something outside > which is orchestrating the HA cfg. > > On Tue, Aug 11, 2020 at 11:46 AM Paul Förster > wrote: > > Hi David, > > > On 11. Aug, 2020, at 17:12, David Gauthier > > wrote: > > > > Hi: > > > > 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 ? > > > > Seems like a lot of work for an app and that it should be more > seamless.  But maybe I'm wrong. > > > > 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 ? > > > > 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=master > > You can always download the current driver from: > https://jdbc.postgresql.org > > Does that help? > > Cheers, > Paul > If it's not seamless to the app, it isn't HA.