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.92) (envelope-from ) id 1j9deH-0004TX-30 for pgsql-general@arkaria.postgresql.org; Wed, 04 Mar 2020 23:41:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j9deF-0003Ix-Ke for pgsql-general@arkaria.postgresql.org; Wed, 04 Mar 2020 23:41:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j9deE-0003Iq-Tm for pgsql-general@lists.postgresql.org; Wed, 04 Mar 2020 23:41:55 +0000 Received: from campbell-lange.net ([178.79.140.51]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9de8-0000wi-4v for pgsql-general@postgresql.org; Wed, 04 Mar 2020 23:41:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=campbell-lange.net; s=it; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=W3ZcdNELVZebSC6wy0GZTcFubz5o6gTjTtIk0HmK+lY=; b=jW59kZolEU8WXMSwSkPaw/47K HgQzf7v8IT+z0ajt/TrtyHGK33M8Dm0D9kiyrMgPUsGbWbGokGEgeRbYJrndXsET8tgkGHUvMNFb2 Lehs8VcTTKx1DSO/KAtpdm2o3vAFo+ucxZR4X9I6vSuLjgMRDUCXONbNch9x+eXhonezo=; Received: from 186.164.198.146.dyn.plus.net ([146.198.164.186] helo=rory-t450s) by campbell-lange.net with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j9de5-0004sK-Od; Wed, 04 Mar 2020 23:41:45 +0000 Received: from rory by rory-t450s with local (Exim 4.92) (envelope-from ) id 1j9deJ-0003tI-J1; Wed, 04 Mar 2020 23:41:59 +0000 Date: Wed, 4 Mar 2020 23:41:59 +0000 From: Rory Campbell-Lange To: "David G. Johnston" Cc: Guyren Howe , Adrian Klaver , PG-General Mailing List Subject: Re: Advice request : simultaneous function/data updates on many databases Message-ID: <20200304234159.GA14088@campbell-lange.net> References: <20200304220426.GB7232@campbell-lange.net> <7ce9074f-0468-1cc8-3337-018b66e56679@aklaver.com> <20200304222257.GA11376@campbell-lange.net> <42b4d82b-d468-3f9e-c021-c20bcc141245@aklaver.com> <20200304223342.GA11628@campbell-lange.net> <20200304224843.GA12333@campbell-lange.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 04/03/20, David G. Johnston (david.g.johnston@gmail.com) wrote: > On Wed, Mar 4, 2020 at 3:55 PM David G. Johnston > wrote: > > > On Wed, Mar 4, 2020 at 3:48 PM Rory Campbell-Lange < > > rory@campbell-lange.net> wrote: > > > >> Any thoughts on how to wrap pl/pgsql function dropping and recreation code > >> within a wrapper pl/pgsql function? > > > > > > Not endorsing this but dynamic SQL works just fine (though can get hard to > > read). Use format() and EXECUTE ... USING liberally. > > > > > Or, more readable depending upon your trust level: > > INSERT INTO dynamic_codes VALUES (1, 'DROP FUNCTION ...'); > > CREATE FUNCTION execute_dynamic(code_id int) > AS $$ > sql_cmd := (SELECT val FROM dynamic_codes WHERE id = code_id); > EXECUTE sql_cmd; > $$; > > SELECT execute_dynamic(1); Thanks very much for the useful examples. Based on your second example, we could drop and then reload a upgrade schema with entries in dynamic_codes then use execute_dynamic(...) as you suggest. Any idea on how to run execute_dynamic across many databases at roughly the same time? I'm just wondering if Guyren Howe's idea of having many transactions open waiting for a clock time to commit is in fact feasible due to (presumably) having to have all the connections open to every database from the client until the transactions complete.