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 1hek1r-0007X4-0N for pgsql-general@arkaria.postgresql.org; Sat, 22 Jun 2019 17:42:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hek1n-0003sX-Me for pgsql-general@arkaria.postgresql.org; Sat, 22 Jun 2019 17:42:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hek1l-0003sQ-Rs for pgsql-general@lists.postgresql.org; Sat, 22 Jun 2019 17:42:15 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hek1c-00010Y-SU for pgsql-general@lists.postgresql.org; Sat, 22 Jun 2019 17:42:13 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 3F9392FF; Sat, 22 Jun 2019 13:42:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sat, 22 Jun 2019 13:42:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=i Cd60CwMebPvROWX0gMWHBK9rDYKiattCqev9nX5yeM=; b=fNz3BaRdSkBwb2Sjg QTdMqRgV/SLV6HIqHNkJczkszoJ+y14MgrX0bTOz9/PSOd0dOZOioLZh1WqSh1+2 HXYXrz5JdXQYDsdj/KhWH3tjelnyShYu0n4Q6WJQ38ZaqkEj+N4xdAoi10Q1tc8/ ERDUW4VnZf1Jd5O194la8POQUaxWULEWSJLUmVLdg4SoTuzkdmPgY38AJ/xXQEFw nBynM39LdcRAFQiywcAqV1JB5Xs/sAd9u7jLoRQLlrH0kPuA4riZCtgLOtG5oWpI d2s8T4zJHtx+fyQGzDhiYA6Pm8bOu6aqYo4vfeRsD7xSRPazsU077zf0QQqYiEVM HfOpQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm3; bh=iCd60CwMebPvROWX0gMWHBK9rDYKiattCqev9nX5y eM=; b=steLMunxIm57QrlyMZfAaUhYJVYkplnXBAebqVM6k6ZGtk8h4UeOLYOZP tRNVs/yKjs4spM1R8kJLgOPprFBBUrBL6FYjTjvnlyFFjJ2VgLqpjDZVW0HyRPkX XCpswEf+xQyUJHrbJs4o42LGBPomDx2G02KKgzXPuDb01s2dRiBX+Xy+D2ozb2ih HFyvrPCAZJVLwnb2e3HYAVWBUmD8b3GNTVqA7iI2gduK3IkBgFRqI8gvHHwzFsOu Kdzo728SVp2Aw8152SC5vuhw9n1cebpI9Ng1HSwyY2E2yyLCENOYsjX5Y0n37nbH CziOoMJ9fZ19mU1xmgQJKGPlV1uMQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrtdekgdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepjedurddvuddvrdduhedtrddvtddvnecurfgrrhgrmhepmhgrihhlfhhr ohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsth gvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 08CA8380076; Sat, 22 Jun 2019 13:41:59 -0400 (EDT) Subject: Re: Row data is reflected in DETAIL message when constraints fail on insert/update To: Karsten Hilbert , pgsql-general@lists.postgresql.org References: <20190620114527.GD30366@hermes.hilbert.loc> <20190620152741.GG30366@hermes.hilbert.loc> <13631.1561047413@sss.pgh.pa.us> <20190621095754.GA2222@hermes.hilbert.loc> <20190622164010.vsyjjkihio4tfz5i@hjp.at> <20190622170941.GA9847@hermes.hilbert.loc> From: Adrian Klaver Message-ID: <227759be-409e-9451-aaec-847c87242886@aklaver.com> Date: Sat, 22 Jun 2019 10:41:59 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: <20190622170941.GA9847@hermes.hilbert.loc> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/22/19 10:09 AM, Karsten Hilbert wrote: > On Sat, Jun 22, 2019 at 06:40:10PM +0200, Peter J. Holzer wrote: > >>> How is it useful in a normally configured database to return row data in >>> error messages? >> >> This is extremely useful. It tells you what data didn't match your >> program's expectations. Otherwise you just get a vague "unique >> constraint violation" > > Sure, except some argue that PG not send such information to > the *client* by *default*, which seems to have some merit > (the default should, however, keep logging such data to the > PG log) Two points: 1) From Tom Lanes post upstream, the client is the one sending the data to the server so it/they already know what it is. 2) Defining the client. In most non-trivial cases there is a stack of clients. For example in the Django framework I use when connecting to a Postgres db there is: a) psycopg2 --the client that the message is actually going to. b) The ORM the client that sits above 1) --though it is possible to bypass this level. c) The views, the clients that sit above 1) & 2) When deploying I ensure the DEBUG setting is set to False to ensure the error does not bubble up from 1) to the end user that is looking at the output of 3). I do capture the errors and log them(to secure file) for use in identifying issues. I also pop up a generic message to the end user based off the db error to give them context for why some action did not happen e.g. duplicate item(key). Therefore for my use cases the detailed information being sent to the low level client(psycopg2) is very useful and essential to fixing problems. What it comes down is that security is situation specific and ever changing. Depending on a generic program be it a database or framework or something else to anticipate all your requirements is unrealistic and ultimately insecure. > > This can lead to the following problem: > >> and you can then search through a hundred million >> rows of data to find that violation. > > which could be solved by passing to the client an identifier > instead of the row data which is also logged to the server > log alongside the row data. The combination of > > %m or %n - timestamp > %c - session ID > %l - in-session log line idx > %e - SQLSTATE > > would probably suffice if sent to the client, given it is > logged in the server log. > > (not that I suggest any such thing as I certainly lack the > skills to provide a patch) > > Karsten > -- > GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B > > > -- Adrian Klaver adrian.klaver@aklaver.com