From: | Charles Clavadetscher <clavadetscher(at)swisspug(dot)org> |
---|---|
To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Proposal "stack trace" like debugging option in PostgreSQL |
Date: | 2016-08-01 11:25:36 |
Message-ID: | 095b09a0-d052-6a3d-83aa-94dbc2f087e3@swisspug.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello
On 08/01/2016 12:15 AM, Tom Lane wrote:
> 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
>
>
Maybe this could help, too.
In the documentation there is a description of how to get the call stack
of functions:
https://www.postgresql.org/docs/current/static/plpgsql-control-structures.html
40.6.7. Obtaining Current Execution Information
The GET [ CURRENT ] DIAGNOSTICS command retrieves information about
current execution state (whereas the GET STACKED DIAGNOSTICS command
discussed above reports information about the execution state as of a
previous error). This command has the form:
GET [ CURRENT ] DIAGNOSTICS variable { = | := } item [ , ... ];
Currently only one information item is supported. Status item PG_CONTEXT
will return a text string with line(s) of text describing the call
stack. The first line refers to the current function and currently
executing GET DIAGNOSTICS command. The second and any subsequent lines
refer to calling functions further up the call stack. For example:
CREATE OR REPLACE FUNCTION outer_func() RETURNS integer AS $$
BEGIN
RETURN inner_func();
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION inner_func() RETURNS integer AS $$
DECLARE
stack text;
BEGIN
GET DIAGNOSTICS stack = PG_CONTEXT;
RAISE NOTICE E'--- Call Stack ---\n%', stack;
RETURN 1;
END;
$$ LANGUAGE plpgsql;
SELECT outer_func();
NOTICE: --- Call Stack ---
PL/pgSQL function inner_func() line 5 at GET DIAGNOSTICS
PL/pgSQL function outer_func() line 3 at RETURN
CONTEXT: PL/pgSQL function outer_func() line 3 at RETURN
outer_func
------------
1
(1 row)
Regards
Charles
--
Swiss PostgreSQL Users Group
c/o Charles Clavadetscher
Treasurer
Motorenstrasse 18
CH – 8005 Zürich
+-----------------------+
| ____ ______ ___ |
| / )/ \/ \ |
| ( / __ _\ ) |
| \ (/ o) ( o) ) |
| \_ (_ ) \ ) _/ |
| \ /\_/ \)/ |
| \/ <//| |\\> |
| _| | |
| \|_/ |
| |
| PostgreSQL 1996-2016 |
| 20 Years of Success |
| |
+-----------------------+
From | Date | Subject | |
---|---|---|---|
Next Message | Moreno Andreo | 2016-08-01 11:48:10 | Re: [SPAM] Re: WAL directory size calculation |
Previous Message | Patrick B | 2016-08-01 00:54:35 | Re: pg_archivecleanup standalone bash script |