Re: good exception handling archiecutre

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: <Atul(dot)Goel(at)globaldatapoint(dot)com> <Atul(dot)Goel(at)globaldatapoint(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: good exception handling archiecutre
Date: 2010-08-16 17:07:05
Message-ID: 5C7E8E00-1C75-415F-9649-58E2A0C23347@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 16 Aug 2010, at 10:45, <Atul(dot)Goel(at)globaldatapoint(dot)com> <Atul(dot)Goel(at)globaldatapoint(dot)com> wrote:

> Hi Alban,
>
> Thanks for the reply.
>
> I checked that Notify will not work till the transaction is commited. So in our case since the transaction is being rolled back there will be no notify.

Ah, you're right! I totally forgot about that...

> Is there any other way of inter process communication in Postgres.

Of course there is :)

There's nothing stopping you from writing a few custom functions in an untrusted language that does your IPC for you. C comes to mind, but PL/Perlu, PL/PythonU, etc. should be able to do it as well (and probably easier).

Usually if you're talking about performing I/O external to the database you'll get warned that transactions involving those calls can't be rolled back, but in this case that's exactly what you want.

Now I know that Postgres uses some IPC internally as well (at least shared memory), so maybe it's possible to use some of the internal mechanisms. I have no idea whether that's possible or at all advisable, I'm sure someone (probably Tom) will chime in regarding that.

Cheers!

> -----Original Message-----
> From: Alban Hertroys [mailto:dalroi(at)solfertje(dot)student(dot)utwente(dot)nl]
> Sent: 13 August 2010 17:50
> To: Atul Goel
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] good exception handling archiecutre
>
> On 13 Aug 2010, at 14:07, <Atul(dot)Goel(at)globaldatapoint(dot)com> <Atul(dot)Goel(at)globaldatapoint(dot)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 the external 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 a separate 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.
>
>
>
>
>
> This e-mail is confidential and should not be used by anyone who is not the original intended recipient. Global DataPoint Limited does not accept liability for any statements made which are clearly the sender's own and not expressly made on behalf of Global DataPoint Limited. No contracts may be concluded on behalf of Global DataPoint Limited by means of e-mail communication. Global DataPoint Limited Registered in England and Wales with registered number 3739752 Registered Office Middlesex House, 34-42 Cleveland Street, London W1T 4LB
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

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,4c697052967632122118857!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karl Denninger 2010-08-16 17:40:03 Encoding change question...
Previous Message Stefan Wild 2010-08-16 16:43:25 Re: Wrong "ORDER BY" on a numeric value result