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 1ion51-0001r1-KQ for pgsql-general@arkaria.postgresql.org; Tue, 07 Jan 2020 11:31:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ion4y-0003NW-SB for pgsql-general@arkaria.postgresql.org; Tue, 07 Jan 2020 11:31:20 +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 1ion4y-0003NO-F1 for pgsql-general@lists.postgresql.org; Tue, 07 Jan 2020 11:31:20 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ion4v-00089D-Oz for pgsql-general@lists.postgresql.org; Tue, 07 Jan 2020 11:31:19 +0000 Received: by mail-wr1-x443.google.com with SMTP id g17so53506477wro.2 for ; Tue, 07 Jan 2020 03:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=ZlBsRm6uE3aliKAbwWsgRZbv48T0Wq+XCRUMA62UFc8=; b=iF7OMVce6Y+vAMMt5sZVrztRUbsRoy7jWlzhI72ht1ZNe2wfhpNwJAPnLFdsmRPIS3 PnGtlA5qv5BBINfae2zFwxkPDVOGLrVJOcKp2gDUxkJtG0VuFHd249zl/Bghn84esciC Pf1B6JoRpiWzxAo/0JJb428JBfBk0DuijsDlxriI1qWjHY30dr0be9ZkrseS+stWTFX1 Hp/ykKvE8f7mpX1U4hfQ81PwTeWGqyVMrdzs/r+OA69IJWqRgiy7A3R1nyntKsBGFLsd oRr5HNmiexvYJBOG4jxKb3NvHIvb7SP+Perc7pU5aaNtnKdPtr+WQlUZYQWL0rm5r2oA lh0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=ZlBsRm6uE3aliKAbwWsgRZbv48T0Wq+XCRUMA62UFc8=; b=guCZudxooi3F7/83lmt0yPatqvKvDSGfCloZHOBfm+glI1tfPBeOthqDefs2gJo+qH BYuhLi3x6c+Czgg0h+4/NycZcx0trSOSCACYpnnVQCg2a3Khx+1olN8ZrqUVEQ7juuCk dTPmkBWz4VlBEwUZxOUm9Zk6O14sRkyP4L6PR6KJPDkC0hg3LYusDq+vOIVTFgZ3PyHT CPrzAJbo4gj+w20YM4gMHC3+taj6SCZu9asAd5fWTWjuGT9W6WA3xFclF6J/gSmqZdHv WhkUIHAspUCXwoxo/52X15BY79lzkyMqPkuzm05k4WqMct7wKDvmNRmSLyq5e88I13Vy Q4vA== X-Gm-Message-State: APjAAAXAtjW47TgcZ7CHVzv+2a0ykfGmQ1sRUD8MVlZzePLi9PgiVaMD M7L1UxcNKfdd4aHks8oUBCu8ONvB2EU= X-Google-Smtp-Source: APXvYqwplhjnSHXE+YaZKg4L/nCF7ZxQEJWm11yYSfaGmnOlwNF2HTq6SVvucSYNl2kdiqWvXBAxsg== X-Received: by 2002:adf:a285:: with SMTP id s5mr21846921wra.118.1578396675370; Tue, 07 Jan 2020 03:31:15 -0800 (PST) Received: from localhost.localdomain ([212.186.219.234]) by smtp.gmail.com with ESMTPSA id m3sm75567653wrs.53.2020.01.07.03.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 03:31:14 -0800 (PST) Message-ID: <20efbcebaf14f79e24d28ac53db14533b0c201f8.camel@cybertec.at> Subject: Re: How to reset a server error '25P02 in_failed_sql_transaction' From: Laurenz Albe To: Matthias Apitz , pgsql-general@lists.postgresql.org Date: Tue, 07 Jan 2020 12:31:14 +0100 In-Reply-To: <20191231055501.GA2812@c720-r342378> References: <20191231055501.GA2812@c720-r342378> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 2019-12-31 at 06:55 +0100, Matthias Apitz wrote: > Due to a wrong human input in the GUI of our application our > application server, from the point of view of the PostgreSQL server it > is the PostgreSQL client, issues a broken ESQL/C command to the PostgreSQL > server, here from our own debug logging the command and the error > message of the server: > > > posDebug: [27.12.2019 15:20:59:043] stmt: SELECT ctid, * from titel_datum WHERE desk>='*2019' AND feldnr IN ( 2 ) ORDER BY desk ASC , feldnr ASC > posDebug: [27.12.2019 15:20:59:043] ESQL: PREPARE sid_titel_datum FROM :select_anw; > ==== sqlca ==== > sqlcode: -400 > sqlerrm.sqlerrml: 61 > sqlerrm.sqlerrmc: invalid input syntax for type date: »*2019« on line 918 > ... > > All subsequent correct (SELECT ...) statements get rejected with, for example: > > > ... > posDebug: [27.12.2019 15:20:59:044] stmt: SELECT ctid, * from titel_datum WHERE desk>='31.12.1900' AND feldnr IN ( 2 ) ORDER BY desk ASC , feldnr ASC > posDebug: [27.12.2019 15:20:59:044] ESQL: PREPARE sid_titel_datum FROM :select_anw; > ==== sqlca ==== > sqlcode: -400 > sqlerrm.sqlerrml: 105 > sqlerrm.sqlerrmc: current transaction is aborted, commands ignored until end of transaction block on line 918 > sqlerrd: 0 0 0 0 0 0 > sqlwarn: 0 0 0 0 0 0 0 0 > sqlstate: 25P02 > ========posSqlError======= > ... > > Note: we are not in some kind TRANSACTION block, like 'EXEC SQL BEGIN TRANSACTION;' > > What is the correct way to abort the "transaction" as requested by the PG > server to return to normal operations? Then you must have "autocommit" set to "off", and you must catch the error in your code and issue an explicit rollback. Maybe you should have a look at your transaction management in general, because it is very important that COMMIT is issued once any transaction is completed. COMMIT on an aborted transaction will automatically cause a rollback. Did you make sure that your code is not vulnerable to SQL injection? What is the statement if the user enters a single quote for the date? Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com