Обсуждение: getting async raise notice messages

Поиск
Список
Период
Сортировка

getting async raise notice messages

От
Pawel Veselov
Дата:
Hi.

Is it possible to get output of raise notice statements as produced by a PL function, as the function is being executed? And if yes, what version was that introduced in?

Thank you,
  Pawel.

Re: getting async raise notice messages

От
Dave Cramer
Дата:

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:06, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Hi.

Is it possible to get output of raise notice statements as produced by a PL function, as the function is being executed? And if yes, what version was that introduced in?

Thank you,
  Pawel.


Re: getting async raise notice messages

От
Pawel Veselov
Дата:
Dave,

On Mon, Jan 26, 2015 at 2:38 PM, Dave Cramer <pg@fastcrypt.com> wrote:

Dave Cramer

I've seen that :) May be I'm missing something, but that's not asynchronous. I need to wait until statement finishes before calling those getWarnings() methods. May be I can call them from another thread (at least on Connection/Statement object) as the SQL is being processed, and they will return current messages, but I'm not sure when to - i.e. how do I know when a new message has been made available.
 
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:06, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Hi.

Is it possible to get output of raise notice statements as produced by a PL function, as the function is being executed? And if yes, what version was that introduced in?

 

Re: getting async raise notice messages

От
Dave Cramer
Дата:
Pawel,

Have a look at org/postgresql/test/jdbc2/NotifyTest.java for exactly what you proposed. As for when it gets notified, I do not know how you would tell as the spec does not provide this functionality (AFAIK)

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:52, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Dave,

On Mon, Jan 26, 2015 at 2:38 PM, Dave Cramer <pg@fastcrypt.com> wrote:

Dave Cramer

I've seen that :) May be I'm missing something, but that's not asynchronous. I need to wait until statement finishes before calling those getWarnings() methods. May be I can call them from another thread (at least on Connection/Statement object) as the SQL is being processed, and they will return current messages, but I'm not sure when to - i.e. how do I know when a new message has been made available.
 
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:06, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Hi.

Is it possible to get output of raise notice statements as produced by a PL function, as the function is being executed? And if yes, what version was that introduced in?

 

Re: getting async raise notice messages

От
Kevin Wooten
Дата:
We support asynchronous LISTEN/NOTIFY… https://github.com/impossibl/pgjdbc-ng

I wasn’t sure that’s exactly what you were asking about.  After connection use PGConnection.addNotificationListener to add asynchronous listeners.

On Jan 26, 2015, at 4:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:

Pawel,

Have a look at org/postgresql/test/jdbc2/NotifyTest.java for exactly what you proposed. As for when it gets notified, I do not know how you would tell as the spec does not provide this functionality (AFAIK)

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:52, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Dave,

On Mon, Jan 26, 2015 at 2:38 PM, Dave Cramer <pg@fastcrypt.com> wrote:

Dave Cramer

I've seen that :) May be I'm missing something, but that's not asynchronous. I need to wait until statement finishes before calling those getWarnings() methods. May be I can call them from another thread (at least on Connection/Statement object) as the SQL is being processed, and they will return current messages, but I'm not sure when to - i.e. how do I know when a new message has been made available.
 
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:06, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Hi.

Is it possible to get output of raise notice statements as produced by a PL function, as the function is being executed? And if yes, what version was that introduced in?

 


Re: getting async raise notice messages

От
Pawel Veselov
Дата:
On Mon, Jan 26, 2015 at 3:42 PM, Dave Cramer <pg@fastcrypt.com> wrote:
Pawel,

Have a look at org/postgresql/test/jdbc2/NotifyTest.java for exactly what you proposed. As for when it gets notified, I do not know how you would tell as the spec does not provide this functionality (AFAIK)

AFAIK too JDBC doesn't. But IMHO, a meaningful (short of polling on a timer, which makes it either CPU intensive, or delayed) LISTEN/NOTIFY application is not particularly possible without a mechanism that will somehow call into the app to notify that a notification is ready.

Also, 'raise notice' from a statement is treated as SQLWarning by the driver, not a notification. I've poked around the source and it's actually quite tricky. Warnings that come out anything but the result response are attached directly to the connection. But the result warnings are sent through some cumbersome (to me :) ) chain of handlers.

I've put together this patch (over 9.1-902, which is just what I currently use), if anybody's interested: http://pastebin.com/KftdtdNq ,but:
- it uses JDK6 stuff
- has effect of copying all statements/resultset warnings into connection warnings

Also, thank you, Kevin. May be I'll try out the NG driver once I upgrade the project JDK :)

Thanks,
  Pawel.
 

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:52, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Dave,

On Mon, Jan 26, 2015 at 2:38 PM, Dave Cramer <pg@fastcrypt.com> wrote:

Dave Cramer

I've seen that :) May be I'm missing something, but that's not asynchronous. I need to wait until statement finishes before calling those getWarnings() methods. May be I can call them from another thread (at least on Connection/Statement object) as the SQL is being processed, and they will return current messages, but I'm not sure when to - i.e. how do I know when a new message has been made available.
 
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 26 January 2015 at 17:06, Pawel Veselov <pawel.veselov@gmail.com> wrote:
Hi.

Is it possible to get output of raise notice statements as produced by a PL function, as the function is being executed? And if yes, what version was that introduced in?

 




--
With best of best regards
Pawel S. Veselov

Re: getting async raise notice messages

От
Pawel Veselov
Дата:

[skipped]
 
I've put together this patch (over 9.1-902, which is just what I currently use), if anybody's interested: http://pastebin.com/KftdtdNq ,but:
- it uses JDK6 stuff
- has effect of copying all statements/resultset warnings into connection warnings

And one other thing. That's not asynchronous, it simply provides callbacks into the caller's app to allow to process notifications as they are received.

[skipped]

Re: getting async raise notice messages

От
Dave Cramer
Дата:
Pawel,

Thanks, this looks interesting.

1) why are you using such an old driver?
2) what are you referring to with the comment about it not being async?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 27 January 2015 at 17:33, Pawel Veselov <pawel.veselov@gmail.com> wrote:

[skipped]
 
I've put together this patch (over 9.1-902, which is just what I currently use), if anybody's interested: http://pastebin.com/KftdtdNq ,but:
- it uses JDK6 stuff
- has effect of copying all statements/resultset warnings into connection warnings

And one other thing. That's not asynchronous, it simply provides callbacks into the caller's app to allow to process notifications as they are received.

[skipped]

Re: getting async raise notice messages

От
Pawel Veselov
Дата:

Hi Dave.

On Wed, Jan 28, 2015 at 2:38 AM, Dave Cramer <pg@fastcrypt.com> wrote:
Pawel,

Thanks, this looks interesting.

1) why are you using such an old driver?

Only for the "If it ain't broke, don't touch it" principle :) It's a part of a large J2EE application. Will probably update it along with other middleware at some point. 
 
2) what are you referring to with the comment about it not being async?

My original question was about "async notifications". Technically async in this case would mean calling back on a separate thread. This fix calls back on the same thread. So it needs to be realized that any work inside that call back will affect the execution of the statement.
 

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 27 January 2015 at 17:33, Pawel Veselov <pawel.veselov@gmail.com> wrote:

[skipped]
 
I've put together this patch (over 9.1-902, which is just what I currently use), if anybody's interested: http://pastebin.com/KftdtdNq ,but:
- it uses JDK6 stuff
- has effect of copying all statements/resultset warnings into connection warnings

And one other thing. That's not asynchronous, it simply provides callbacks into the caller's app to allow to process notifications as they are received.

[skipped]


--
With best of best regards
Pawel S. Veselov

Re: getting async raise notice messages

От
Dave Cramer
Дата:
Hi Pawel,

Got it, thanks for the explanation

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 28 January 2015 at 14:55, Pawel Veselov <pawel.veselov@gmail.com> wrote:

Hi Dave.

On Wed, Jan 28, 2015 at 2:38 AM, Dave Cramer <pg@fastcrypt.com> wrote:
Pawel,

Thanks, this looks interesting.

1) why are you using such an old driver?

Only for the "If it ain't broke, don't touch it" principle :) It's a part of a large J2EE application. Will probably update it along with other middleware at some point. 
 
2) what are you referring to with the comment about it not being async?

My original question was about "async notifications". Technically async in this case would mean calling back on a separate thread. This fix calls back on the same thread. So it needs to be realized that any work inside that call back will affect the execution of the statement.
 

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On 27 January 2015 at 17:33, Pawel Veselov <pawel.veselov@gmail.com> wrote:

[skipped]
 
I've put together this patch (over 9.1-902, which is just what I currently use), if anybody's interested: http://pastebin.com/KftdtdNq ,but:
- it uses JDK6 stuff
- has effect of copying all statements/resultset warnings into connection warnings

And one other thing. That's not asynchronous, it simply provides callbacks into the caller's app to allow to process notifications as they are received.

[skipped]


--
With best of best regards
Pawel S. Veselov