Re: good exception handling archiecutre

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: good exception handling archiecutre
Дата
Msg-id 00430069-029E-4269-8ED8-7F3C07BF4003@solfertje.student.utwente.nl
обсуждение исходный текст
Ответ на good exception handling archiecutre  (<Atul.Goel@globaldatapoint.com>)
Ответы Re: good exception handling archiecutre  (<Atul.Goel@globaldatapoint.com>)
Список pgsql-general
On 13 Aug 2010, at 14:07, <Atul.Goel@globaldatapoint.com> <Atul.Goel@globaldatapoint.com> wrote:

> How can we do error logging in Postgres. I am trying to create a LOG_AND_STOP method which would be generic to the
code.I have pasted the code I have written. This code returns no data which is understandable as the error is thrown to
theexternal world. 
>
> Can I write the code somehow.
>
> CREATE SCHEMA test
>   AUTHORIZATION postgres;
>
> CREATE TABLE test.error_log
> (
>   error_desc text
> );
>
>
> CREATE OR REPLACE FUNCTION test.log_and_stop(err_desc text)
>   RETURNS void AS
> $BODY$
> Declare
> x integer;
> begin
> begin
> insert into test.error_log values (err_desc);
> end;
> begin
> raise exception '%',err_desc;

Your transaction got rolled back here, hence the lack of data in your error_log table.

I don't think there's any way to log errors into a table from within the same transaction, you'll probably need to use
aseparate connection for the logging. I think LISTEN/NOTIFY may come in handy there. 

> end;
> end;
> $BODY$
>   LANGUAGE 'plpgsql' VOLATILE
>   COST 100;
> ALTER FUNCTION test.log_and_stop(text) OWNER TO postgres;

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4c6577d7967632072599737!



В списке pgsql-general по дате отправления:

Предыдущее
От: Karl Denninger
Дата:
Сообщение: Re: Compression on SSL links?
Следующее
От: Maciek Sakrejda
Дата:
Сообщение: log_statement / log_duration / log_min_duration_statement and SPI?