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.89) (envelope-from ) id 1iykIv-00067O-KC for pgsql-general@arkaria.postgresql.org; Mon, 03 Feb 2020 22:34:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iykIt-0001vJ-HB for pgsql-general@arkaria.postgresql.org; Mon, 03 Feb 2020 22:34:51 +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 1iykIt-0001vC-2Z for pgsql-general@lists.postgresql.org; Mon, 03 Feb 2020 22:34:51 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iykIq-0004MA-Dq for pgsql-general@postgresql.org; Mon, 03 Feb 2020 22:34:49 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 8BB07220AF; Mon, 3 Feb 2020 17:34:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 03 Feb 2020 17:34:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=z 3B4A25hi2dsmD31MPqxvxXFJIFdrsyaw+PoZ3C42+8=; b=JfZrLvOFeQ2achC9p ShpwEtk4bJHTiP0d3HxcayyuOmjOvucVJaT0y4Az36PY0etDhJ42L+QCykygkP0k vi2aJz98rz+1D0xw1hVd/+Z9RrptDTx4e3E+7e1Pg35PVxyj8+n8A5isPRUxkC6j u4P07ORez+pPxR7lSKR6R6tqFqbatSK9CA2d4IRZ2f1+9mOaOAT3vdDuWFr458RR 77tNIBS6CDHdh5CUyE3eBvD5rSP6p6mTE/8AH1PWmR01aksNHBa/GCxvOLMk2Ycy tcUEsL6DyWa0NW65krm17Y7RaJ88GSMBvHtaG41/P/p6UFdaboIQsKcenh447j/9 odKaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=z3B4A25hi2dsmD31MPqxvxXFJIFdrsyaw+PoZ3C42 +8=; b=BYz6W3oKvE/w3W5lbHJDS9Ph+OZyM6ahFj7G4gK1c/v30xdvtzHZ4tDWs xd10BtGDCcF0ATNflEw8jNUq6zER0SREipLNNGfnkKQuY/HznOGLcRfl3RJ56wwp dGrwSGLlTRDhPjn5+ESIm8zE2je+yPGeUG3+CMMJ/R1bu5MB9mY/at+aRrMy351n Z6AJhvIK4NpgfALhYg/cS+nMsP2moe0KxLVWXMPLPpmbQRTqQRR2Gdimj4G9t5FD DEUMU8iJz9o/RshgUGebfRIfiqRBkI9UMpzACxWy7+yETZQ2bo/NIwtswwjePTfS mH7ePjGRnS/SbrzqGUiTE+ZKO7Wig== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgeejgdduheelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppeejuddrvdduvddruddvledrud elfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegr ughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id F21DF3060304; Mon, 3 Feb 2020 17:34:46 -0500 (EST) Subject: Re: Postgres Crashing To: Doug Roberts References: Cc: pgsql-general From: Adrian Klaver Message-ID: Date: Mon, 3 Feb 2020 14:34:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/3/20 2:18 PM, Doug Roberts wrote: Please reply to list also. Ccing list. > Adrian, > > Here is what the reset recirc function is doing. > > CREATE OR REPLACE FUNCTION containers_reset_recirc > ( >     in_uid INTEGER > ) > RETURNS INTEGER > AS $BODY$ >     DECLARE regex VARCHAR(50); > BEGIN >     SELECT concat(',*', in_uid, '=\d+,*') INTO regex; > >     LOCK TABLE containers IN SHARE ROW EXCLUSIVE MODE; > >     UPDATE containers >         SET recirculation_count = >             case >                 when substring(recirculation_count, regex) like ',%,' then >                     regexp_replace(recirculation_count, regex, ',') >                 else >                     regexp_replace(recirculation_count, regex, '') >                 end; > >     RETURN in_uid; > END; > > Containers add/update is basically updating a specific container using > the values that were passed to the function. So how did containers_reset_recirc() come to clash with containers_add_update()? > > UPDATE containers >     SET type_uid = COALESCE(declared_type_uid, type_uid), >         carton_type_uid = COALESCE(declared_carton_type_uid, > carton_type_uid), >         status_uid = COALESCE(declared_status_uid, status_uid), >         order_uid = COALESCE(in_order_uid, order_uid), >         wave_uid = COALESCE(in_wave_uid, wave_uid), >         length = COALESCE(in_length, carton_length, length), >         width = COALESCE(in_width, carton_width, width), >         height = COALESCE(in_height, carton_height, height), >         weight = COALESCE(in_weight, weight), >         weight_minimum = COALESCE(in_weight_minimum, weight_minimum), >         weight_maximum = COALESCE(in_weight_maximum, weight_maximum), >         weight_expected = COALESCE(in_weight_expected, weight_expected), >         first_seen_decision_point_id = > COALESCE(first_seen_decision_point_id, in_last_seen_decision_point_id), >         first_seen_datetime = COALESCE(first_seen_datetime, > last_seen_date_time), >         last_seen_decision_point_id = > COALESCE(in_last_seen_decision_point_id, last_seen_decision_point_id), >         last_seen_datetime = COALESCE(last_seen_date_time, > last_seen_datetime), >         recirculation_count = COALESCE(in_recirculation_count, > recirculation_count), >         project_flags = COALESCE(in_project_flags, project_flags), >         passed_weight_check = COALESCE(in_passed_weight_check, > passed_weight_check) >     WHERE uid = in_uid > > Thanks, > > Doug > > On Mon, Feb 3, 2020 at 4:49 PM Adrian Klaver > wrote: > > On 2/3/20 1:43 PM, Doug Roberts wrote: > > Hello, > > > > I'm having an issue where a process in Postgres is crashing and > cause > > the server to go into recovery mode. > > > > I'm getting the following errors in the log. > > > > 2020-02-03 14:12:57.473 EST [11992] [0]WARNING:  57P02: terminating > > connection because of crash of another server process > > 2020-02-03 14:12:57.473 EST [11992] [0]DETAIL:  The postmaster has > > commanded this server process to roll back the current > transaction and > > exit, because another server process exited abnormally and possibly > > corrupted shared memory. > > 2020-02-03 14:12:57.473 EST [11992] [0]HINT:  In a moment you > should be > > able to reconnect to the database and repeat your command. > > 2020-02-03 14:12:57.473 EST [11992] [0]CONTEXT:  while locking tuple > > (4101,2) in relation "containers" > > SQL statement "UPDATE containers > >             SET type_uid = COALESCE(declared_type_uid, type_uid), > >                 carton_type_uid = COALESCE(declared_carton_type_uid, > > carton_type_uid), > >                 status_uid = COALESCE(declared_status_uid, > status_uid), > >                 order_uid = COALESCE(in_order_uid, order_uid), > >                 wave_uid = COALESCE(in_wave_uid, wave_uid), > >                 length = COALESCE(in_length, carton_length, length), > >                 width = COALESCE(in_width, carton_width, width), > >                 height = COALESCE(in_height, carton_height, height), > >                 weight = COALESCE(in_weight, weight), > >                 weight_minimum = COALESCE(in_weight_minimum, > > weight_minimum), > >                 weight_maximum = COALESCE(in_weight_maximum, > > weight_maximum), > >                 weight_expected = COALESCE(in_weight_expected, > > weight_expected), > >                 first_seen_decision_point_id = > > COALESCE(first_seen_decision_point_id, > in_last_seen_decision_point_id), > >                 first_seen_datetime = COALESCE(first_seen_datetime, > > last_seen_date_time), > >                 last_seen_decision_point_id = > > COALESCE(in_last_seen_decision_point_id, > last_seen_decision_point_id), > >                 last_seen_datetime = COALESCE(last_seen_date_time, > > last_seen_datetime), > >                 recirculation_count = > COALESCE(in_recirculation_count, > > recirculation_count), > >                 project_flags = COALESCE(in_project_flags, > project_flags), > >                 passed_weight_check = > COALESCE(in_passed_weight_check, > > passed_weight_check) > >             WHERE uid = in_uid" > > PL/pgSQL function > > > containers_add_update(integer,integer,integer,integer,integer,integer,double > > > precision,double precision,double precision,double precision,double > > precision,double precision,double precision,integer,timestamp > without > > time zone,character varying,bigint,boolean) line 60 at SQL statement > > > > > This happened when I was using a function to remove part of a comma > > delimited string while updating a row. The update could potentially > > touch every row in the table. The issue above occurred when a > different > > update function was being executed on the same table. > > The full content of containers_add_update() would be helpful as well as > the content of the other function. If that is not possible some idea of > the order in which they where run as well as where the LOCK TABLE below > was inserted? > > > > > If I use the following lock this issue seems to be resolved. > However, > > I'm not sure why the above issue occurred. > > > > LOCK TABLE containers IN SHARE ROW EXCLUSIVE MODE; > > > > Does anyone have any ideas? > > > > Thanks, > > > > Doug > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > -- Adrian Klaver adrian.klaver@aklaver.com