Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WqOjG-0005bl-LJ for pgsql-bugs@arkaria.postgresql.org; Fri, 30 May 2014 15:28:23 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WqOjG-0005J8-2V for pgsql-bugs@arkaria.postgresql.org; Fri, 30 May 2014 15:28:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WqOjE-0005G8-35 for pgsql-bugs@postgresql.org; Fri, 30 May 2014 15:28:20 +0000 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1WqOjA-0005UK-BM for pgsql-bugs@postgresql.org; Fri, 30 May 2014 15:28:18 +0000 Received: by mail-wi0-f178.google.com with SMTP id cc10so1324094wib.17 for ; Fri, 30 May 2014 08:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=7miwuDwM9Mf5ShPZTbT8myk2PPIjXnHWstYa8hvuRXM=; b=MXktsahFq9rk4GXNlK2ZGtAL6N8jo9p0frL2cTciLYPStmGE1C9HWPOltcCrPhjPk4 eOmh3Jl+7K0M3L6Vcf+NmC1NFxfkxy7WRQqVf62NlJFyGYrVzKbjJXsUAy/peyrFj8v0 3Qd/RAbJL3XRlnfsHda6YyoREOxiY8yY9KfVOnoCqKa6Egu4P6gMSAsLrTMlEPLvHrBE yqIiBl6ODHbVvoEhgBiX66HKn3TwbQz/cVM50vWvLIx40ZrlJNBhpz6oeVEIejhOCzyu YP2Nflwbet53D6rVUFmLLHCfLpNSuN3DDtTL64AL+jty9fF0k497Z1oCFzIlzS+Txwrn aTow== X-Received: by 10.180.82.133 with SMTP id i5mr7920618wiy.50.1401463692252; Fri, 30 May 2014 08:28:12 -0700 (PDT) Received: from localhost (ge-19-117-20.service.infuturo.it. [151.19.117.20]) by mx.google.com with ESMTPSA id dk10sm4435587wib.1.2014.05.30.08.28.07 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 30 May 2014 08:28:11 -0700 (PDT) Date: Fri, 30 May 2014 17:28:03 +0200 From: Sandro Santilli To: pgsql-bugs@postgresql.org Cc: Andres Freund Subject: Re: uninterruptable loop: concurrent delete in progress within table Message-ID: <20140530152803.GA13871@localhost> References: <20140530143150.GA11051@localhost> <20140530144535.GA30516@awork2.anarazel.de> <20140530145910.GC11051@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gBBFr7Ir9EOA20Yy" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20140530145910.GC11051@localhost> User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, May 30, 2014 at 04:59:10PM +0200, Sandro Santilli wrote: > On Fri, May 30, 2014 at 04:45:35PM +0200, Andres Freund wrote: > > Hi, > > > > On 2014-05-30 16:31:50 +0200, Sandro Santilli wrote: > > > The attached script shows a plpgsql function that enters > > > an infinite loop which is not interrupted by statement_timeout. > > > > There's nothing attached... :) > > Oops, sorry. > I've sent (and will send) on request to interested parties. Actually, I further reduced it to not rely on PostGIS and it is attached here. --strk; ()  ASCII ribbon campaign -- Keep it simple ! /\  http://strk.keybit.net/rants/ascii_mails.txt --gBBFr7Ir9EOA20Yy Content-Type: application/x-sql Content-Disposition: attachment; filename="crash.sql" Content-Transfer-Encoding: quoted-printable DROP TABLE crash9;=0A= CREATE TABLE crash9 (=0A= field1 text,=20=0A= field2 timestamptz=20=0A= );=0A= =0A= =0A= COPY crash9 (field1, field2) FROM stdin;=0A= 0106000020E610000000000000 2012-06-06 21:59:08.49036=0A= \N \N=0A= \.=0A= =0A= SET client_min_messages TO DEBUG;=0A= SET statement_timeout TO 100;=0A= =0A= DO $$=0A= DECLARE=0A= sql TEXT;=0A= rec RECORD;=0A= had_column BOOLEAN;=0A= i INTEGER;=0A= new_name TEXT;=0A= reloid REGCLASS;=0A= BEGIN=0A= =0A= reloid :=3D 'crash9'::regclass;=0A= =0A= -- Ensure required fields exist=0A= =0A= -- We need field2=20=0A= FOR rec IN SELECT * FROM ( VALUES ('field2') ) t(cname)=0A= LOOP --{=0A= new_name :=3D null;=0A= << column_setup >>=0A= LOOP --{=0A= had_column :=3D FALSE;=0A= BEGIN=0A= sql :=3D 'ALTER TABLE ' || reloid::text || ' ADD ' || rec.cname=0A= || ' TIMESTAMPTZ NOT NULL DEFAULT now()';=0A= RAISE DEBUG 'Running %', sql;=0A= EXECUTE sql;=0A= EXIT column_setup;=0A= EXCEPTION=0A= WHEN duplicate_column THEN=0A= RAISE NOTICE 'Column % already exists', rec.cname;=0A= had_column :=3D TRUE;=0A= WHEN others THEN=0A= RAISE EXCEPTION '%.%: % (%)',=0A= reloid, rec.cname, SQLERRM, SQLSTATE;=0A= END;=0A= =0A= IF had_column THEN=0A= =0A= -- Ensure data type is a TIMESTAMP WITH TIMEZONE=0A= sql :=3D 'ALTER TABLE ' || reloid::text=0A= || ' ALTER ' || rec.cname=0A= || ' SET NOT NULL,'=0A= || ' ALTER ' || rec.cname=0A= || ' SET DEFAULT now()';=0A= BEGIN=0A= RAISE DEBUG 'Running %', sql;=0A= EXECUTE sql;=0A= EXIT column_setup;=0A= EXCEPTION=0A= WHEN not_null_violation THEN -- failed not-null=0A= RAISE NOTICE '%, renaming', SQLERRM;=0A= WHEN cannot_coerce THEN -- failed cast=0A= RAISE NOTICE '%, renaming', SQLERRM;=0A= WHEN others THEN=0A= RAISE EXCEPTION '%.%: % (%)',=0A= reloid, rec.cname, SQLERRM, SQLSTATE;=0A= END;=0A= =0A= -- invalid column, need rename and re-create it=0A= i :=3D 0;=0A= << rename_column >>=0A= LOOP --{=0A= new_name :=3D '_' || rec.cname || i;=0A= BEGIN=0A= sql :=3D 'ALTER TABLE ' || reloid::text || ' RENAME COLUMN ' ||= rec.cname || ' TO ' || new_name;=0A= RAISE DEBUG 'Running %', sql;=0A= EXECUTE sql;=0A= EXCEPTION=0A= WHEN duplicate_column THEN=0A= i :=3D i+1;=0A= CONTINUE rename_column;=0A= WHEN others THEN=0A= RAISE EXCEPTION 'renaming %.%: % (%)',=0A= reloid, rec.cname, SQLERRM, SQLSTATE;=0A= END;=0A= EXIT rename_column;=0A= END LOOP; --}=0A= CONTINUE column_setup;=0A= =0A= END IF;=0A= END LOOP; -- }=0A= =0A= -- Try to copy data from new name if possible=0A= IF new_name IS NOT NULL THEN -- {=0A= RAISE NOTICE 'Trying to recover data from % coumn', new_name;=0A= BEGIN=0A= -- Copy existing values to new field=0A= sql :=3D 'UPDATE ' || reloid::text || ' SET ' || rec.cname || ' =3D= '=0A= || new_name || '::timestamptz';=0A= RAISE DEBUG 'Running %', sql;=0A= EXECUTE sql;=0A= =0A= EXCEPTION=0A= WHEN others THEN=0A= RAISE NOTICE 'Could not initialize % with existing values: % (%)',= =0A= rec.cname, SQLERRM, SQLSTATE;=0A= CONTINUE;=0A= END;=0A= END IF; -- }=0A= =0A= END LOOP; -- }=0A= =0A= -- We need field1=20=0A= FOR rec IN SELECT * FROM ( VALUES ('field1',4326) ) t(cname,csrid) LOOP -= -{=0A= << column_setup >> LOOP --{=0A= =0A= << column_fixup >>=0A= LOOP --{=0A= =0A= sql :=3D 'CREATE INDEX ON ' || reloid::text || ' ( ' || rec.cname |= | ')';=0A= RAISE DEBUG 'Running %', sql;=0A= EXECUTE sql;=0A= =0A= -- if we reached this line, all went good=0A= EXIT column_setup;=0A= =0A= END LOOP; -- } column_fixup=20=0A= =0A= RAISE EXCEPTION 'Should not get here';=0A= =0A= END LOOP; -- } column_setup=20=0A= =0A= END LOOP; -- } on expected geometry columns=0A= =0A= END;=0A= $$ LANGUAGE PLPGSQL;=0A= =0A= --gBBFr7Ir9EOA20Yy Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --gBBFr7Ir9EOA20Yy--