pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jim Nasby <Jim.Nasby@BlueTreble.com>
To: Peter Geoghegan <pg@heroku.com>
Cc: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Less than ideal error reporting in pg_stat_statements
Date: Wed, 23 Sep 2015 15:43:12 -0500
Message-ID: <56030EE0.4030008@BlueTreble.com> (raw)
In-Reply-To: <5601E3D1.5010401@BlueTreble.com>
References: <5601D354.5000703@BlueTreble.com>
	<CAM3SWZRo_5ZznTp=Mg5Kh2eq-LjWLVS-BXJwsHe_dS50g34Mfw@mail.gmail.com>
	<5601E3D1.5010401@BlueTreble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

On 9/22/15 6:27 PM, Jim Nasby wrote:
>> + ereport(LOG,
>> +              (errcode(ERRCODE_OUT_OF_MEMORY),
>> +               errmsg("out of memory attempting to pg_stat_statement
>> file"),
>> +               errdetail("file \"%s\": size %lld", PGSS_TEXT_FILE,
>> stat.st_size)));
>>
>> Uh, what?
>
> Oops. I'll fix that and address David's concern tomorrow.

New patch attached. I stripped the size reporting out and simplified the 
conditionals a bit as well.
-- 
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 59b8a2e..c9dcd89 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1892,15 +1892,24 @@ qtext_load_file(Size *buffer_size)
 	}
 
 	/* Allocate buffer; beware that off_t might be wider than size_t */
-	if (stat.st_size <= MaxAllocSize)
-		buf = (char *) malloc(stat.st_size);
-	else
-		buf = NULL;
+	if (stat.st_size > MaxAllocSize)
+	{
+		ereport(LOG,
+			 	/* Is there a better code to use? IE: SQLSTATE 53000, 53400 or 54000 */
+				(errcode(ERRCODE_OUT_OF_MEMORY),
+				 errmsg("pg_stat_statement file is too large to process"),
+				 errdetail("file \"%s\"", PGSS_TEXT_FILE.st_size)));
+		CloseTransientFile(fd);
+		return NULL;
+	}
+
+	buf = (char *) malloc(stat.st_size);
+
 	if (buf == NULL)
 	{
 		ereport(LOG,
 				(errcode(ERRCODE_OUT_OF_MEMORY),
-				 errmsg("out of memory")));
+				 errmsg("out of memory attempting to read pg_stat_statement file")));
 		CloseTransientFile(fd);
 		return NULL;
 	}


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

  [text/plain] patch.diff (1.1K, ../56030EE0.4030008@BlueTreble.com/2-patch.diff)
  download | inline diff:
diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index 59b8a2e..c9dcd89 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -1892,15 +1892,24 @@ qtext_load_file(Size *buffer_size)
 	}
 
 	/* Allocate buffer; beware that off_t might be wider than size_t */
-	if (stat.st_size <= MaxAllocSize)
-		buf = (char *) malloc(stat.st_size);
-	else
-		buf = NULL;
+	if (stat.st_size > MaxAllocSize)
+	{
+		ereport(LOG,
+			 	/* Is there a better code to use? IE: SQLSTATE 53000, 53400 or 54000 */
+				(errcode(ERRCODE_OUT_OF_MEMORY),
+				 errmsg("pg_stat_statement file is too large to process"),
+				 errdetail("file \"%s\"", PGSS_TEXT_FILE.st_size)));
+		CloseTransientFile(fd);
+		return NULL;
+	}
+
+	buf = (char *) malloc(stat.st_size);
+
 	if (buf == NULL)
 	{
 		ereport(LOG,
 				(errcode(ERRCODE_OUT_OF_MEMORY),
-				 errmsg("out of memory")));
+				 errmsg("out of memory attempting to read pg_stat_statement file")));
 		CloseTransientFile(fd);
 		return NULL;
 	}


view thread (49+ messages)  latest in thread

Message-ID: <56030EE0.4030008@BlueTreble.com>
Permalink:  ../56030EE0.4030008@BlueTreble.com/
Also on:    postgresql.org/message-id/56030EE0.4030008@BlueTreble.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: Jim.Nasby@BlueTreble.com, pg@heroku.com
  Subject: Re: Less than ideal error reporting in pg_stat_statements
  In-Reply-To: <56030EE0.4030008@BlueTreble.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox