Re: Proposal "stack trace" like debugging option in PostgreSQL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Edson Richter <edsonrichter(at)hotmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Proposal "stack trace" like debugging option in PostgreSQL
Date: 2016-07-31 22:15:45
Message-ID: 13257.1470003345@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Edson Richter <edsonrichter(at)hotmail(dot)com> writes:
>> From: tgl(at)sss(dot)pgh(dot)pa(dot)us
>> Uh, doesn't the CONTEXT field of error messages give you that already?

> Would you give me an example where I can get the info you mention above? Do I need to enable some kind of parameter to get this context field?

Well, you have not mentioned what sort of client environment you are
using, but the server certainly sends that information. In psql,
for example, I can do this:

regression=# create table foo (f1 int primary key, f2 text);
CREATE TABLE
regression=# create function ifoo(int, text) returns void as
$$ begin insert into foo values($1,$2); end $$ language plpgsql;
CREATE FUNCTION
regression=# create function ifoo2(int, text) returns void as
$$ begin perform ifoo($1,$2); end $$ language plpgsql;
CREATE FUNCTION
regression=# select ifoo2(1,'foo');
ifoo2
-------

(1 row)

regression=# select ifoo2(1,'foo');
ERROR: duplicate key value violates unique constraint "foo_pkey"
DETAIL: Key (f1)=(1) already exists.
CONTEXT: SQL statement "insert into foo values($1,$2)"
PL/pgSQL function ifoo(integer,text) line 1 at SQL statement
SQL statement "SELECT ifoo($1,$2)"
PL/pgSQL function ifoo2(integer,text) line 1 at PERFORM

If you're using a misdesigned client that will not show these auxiliary
error fields, you could try looking in the server log --- at default
log verbosity, it will contain that info too. The above test case
gave me this log entry:

ERROR: duplicate key value violates unique constraint "foo_pkey"
DETAIL: Key (f1)=(1) already exists.
CONTEXT: SQL statement "insert into foo values($1,$2)"
PL/pgSQL function ifoo(integer,text) line 1 at SQL statement
SQL statement "SELECT ifoo($1,$2)"
PL/pgSQL function ifoo2(integer,text) line 1 at PERFORM
STATEMENT: select ifoo2(1,'foo');

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message rob stone 2016-07-31 23:28:57 Re: 9.6beta3
Previous Message Patrick B 2016-07-31 22:11:43 pg_archivecleanup standalone bash script