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 1kc9Qk-0004KG-05 for pgsql-general@arkaria.postgresql.org; Mon, 09 Nov 2020 15:50:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kc9Qh-0000Kg-Oa for pgsql-general@arkaria.postgresql.org; Mon, 09 Nov 2020 15:50:03 +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 1kc9Qh-0000KZ-HX for pgsql-general@lists.postgresql.org; Mon, 09 Nov 2020 15:50:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kc9QY-0005vp-S8 for pgsql-general@lists.postgresql.org; Mon, 09 Nov 2020 15:50:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0A9FnqGt1983184; Mon, 9 Nov 2020 10:49:52 -0500 From: Tom Lane To: David Gauthier cc: "pgsql-generallists.postgresql.org" Subject: Re: database aliasing options ? In-reply-to: References: Comments: In-reply-to David Gauthier message dated "Mon, 09 Nov 2020 10:24:04 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1983182.1604936992.1@sss.pgh.pa.us> Date: Mon, 09 Nov 2020 10:49:52 -0500 Message-ID: <1983183.1604936992@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Gauthier writes: > Our IT dept has configured our PG DB as a "High Availability" database. It > has a primary and backup server (disks too). Normally both are running but > if one goes down, the other is still available for use, effectively keeping > the DB up while the failed server is being repaired. > My question has to do with creating and using a DB alias for DB connection > code. Of course the idea would be to toggle which server the alias is > pointing to based on the state of the servers. The idea is to manage which > server is being used OUTSIDE of the DB connection code by changing the > alias. The code always uses the alias. Some people do this by changing the DNS entry for the server. Another thought is that maybe you don't have to do anything dynamic, if you set up the clients with host lists not just single hostnames (that is, "-h host1,host2" or the equivalent). That should work for any libpq-based client. regards, tom lane