Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f80Uj-00048M-Fk for pgsql-general@arkaria.postgresql.org; Mon, 16 Apr 2018 09:32:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f80Ui-00058v-1F for pgsql-general@arkaria.postgresql.org; Mon, 16 Apr 2018 09:32:16 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f80Uh-00058l-MS for pgsql-general@lists.postgresql.org; Mon, 16 Apr 2018 09:32:15 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f80Ud-0005yQ-6T for pgsql-general@postgresql.org; Mon, 16 Apr 2018 09:32:13 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 67DFAC56ED04 for ; Mon, 16 Apr 2018 02:32:09 -0700 (MST) Date: Mon, 16 Apr 2018 02:32:09 -0700 (MST) From: Jack Gao To: pgsql-general@postgresql.org Message-ID: <1523871129422-0.post@n3.nabble.com> In-Reply-To: References: Subject: Re: SQL statement in an error report for deferred constraint violation. MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Konrad Witaszczyk wrote > Hi, > > While PQresultErrorField() from libpq allows to get context in which an > error > occurred for immediate constraints, and thus an SQL statement which caused > the > constraint violation, I cannot see any way to find out which SQL statement > caused an error in case of deferred constraints, in particular deferred > foreign > key constraints. > > Is there any way to check which SQL statement or at least which row > violated a > constraint when it's deferred? If not does anyone know why there is such > restriction? > > > Konrad > > > > signature.asc (981 bytes) > <http://www.postgresql-archive.org/attachment/6015088/0/signature.asc> First of all, you need to locate the problem SQL by modifying log parameters. sed -ir "s/#*logging_collector.*/logging_collector= on/" $PGDATA/postgresql.conf sed -ir "s/#*log_directory.*/log_directory = 'pg_log'/" $PGDATA/postgresql.conf sed -ir "s/#*log_statement.*/log_statement= 'all'/" $PGDATA/postgresql.conf Execute this SQL and send error message in the log. regards Jack Gao -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html