Thread: sigint psql

sigint psql

From
John DeSoi
Date:
I'm communicating with psql via a pipe stream. This works pretty well, 
but one problem I have is trying to cancel an operation. If I send a 
sigint, psql dies. In looking at the source I gather this is because it 
assumes I'm in non-interactive mode (pset.notty is true). I was 
wondering if there was some way to work around this short of 
recompiling the source. I need to do the same thing on Windows.

Thanks for any suggestions,


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



Re: sigint psql

From
Doug McNaught
Date:
John DeSoi <desoi@pgedit.com> writes:

> I'm communicating with psql via a pipe stream. This works pretty well,
> but one problem I have is trying to cancel an operation. If I send a
> sigint, psql dies. In looking at the source I gather this is because
> it assumes I'm in non-interactive mode (pset.notty is true). I was
> wondering if there was some way to work around this short of
> recompiling the source. I need to do the same thing on Windows.
>
> Thanks for any suggestions,

On Unix you could run 'psql' through a pty rather than a pipe.  No
idea what the Windows equivalent would be.

-Doug


Re: sigint psql

From
Bruce Momjian
Date:
Doug McNaught wrote:
> John DeSoi <desoi@pgedit.com> writes:
> 
> > I'm communicating with psql via a pipe stream. This works pretty well,
> > but one problem I have is trying to cancel an operation. If I send a
> > sigint, psql dies. In looking at the source I gather this is because
> > it assumes I'm in non-interactive mode (pset.notty is true). I was
> > wondering if there was some way to work around this short of
> > recompiling the source. I need to do the same thing on Windows.
> >
> > Thanks for any suggestions,
> 
> On Unix you could run 'psql' through a pty rather than a pipe.  No
> idea what the Windows equivalent would be.

We don't have signals on win32 like we have on Unix so we simulate them.
Not sure it is possible to signal psql like you want on Win32.

I just tried 'kill -2 _psql_pid_' on unix and it did cancel the current
query.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: sigint psql

From
"Magnus Hagander"
Date:
>> > I'm communicating with psql via a pipe stream. This works
>pretty well,
>> > but one problem I have is trying to cancel an operation.
>If I send a
>> > sigint, psql dies. In looking at the source I gather this
>is because
>> > it assumes I'm in non-interactive mode (pset.notty is true). I was
>> > wondering if there was some way to work around this short of
>> > recompiling the source. I need to do the same thing on Windows.
>> >
>> > Thanks for any suggestions,
>>
>> On Unix you could run 'psql' through a pty rather than a pipe.  No
>> idea what the Windows equivalent would be.
>
>We don't have signals on win32 like we have on Unix so we
>simulate them.
>Not sure it is possible to signal psql like you want on Win32.

There is no way so signal *psql*, as in the client side process. The
signal emulation only runs in the server.

You can do the same thing in the server using pg_ctl kill, but that
won't work on client processes.

//Magnus


Re: sigint psql

From
John DeSoi
Date:
On Feb 21, 2005, at 3:00 PM, Magnus Hagander wrote:

> There is no way so signal *psql*, as in the client side process. The
> signal emulation only runs in the server.
>
> You can do the same thing in the server using pg_ctl kill, but that
> won't work on client processes.

Thanks to everyone for the feedback and suggestions. Since I need this 
to work on win32, I guess I'll just abort the stream and reconnect. The 
main issue with this is trying to restore any state associated with the 
connection (e.g. search_path).


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



Re: sigint psql

From
John DeSoi
Date:
Hi Magnus,

On Feb 21, 2005, at 3:00 PM, Magnus Hagander wrote:

> There is no way so signal *psql*, as in the client side process. The
> signal emulation only runs in the server.
>

But is there some equivalent of pressing ctrl-C to make psql stop what 
it is doing? For example, through the pipe stream I may execute a \i 
command and the user wants to stop before the file is processed. What 
mechanism is used to do this on win32? I thought it could be 
accomplished on Unix with kill -2, hence my original question. But 
maybe I'm looking in the wrong place.

Thanks,


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL



Re: sigint psql

From
Bruce Momjian
Date:
John DeSoi wrote:
> Hi Magnus,
> 
> On Feb 21, 2005, at 3:00 PM, Magnus Hagander wrote:
> 
> > There is no way so signal *psql*, as in the client side process. The
> > signal emulation only runs in the server.
> >
> 
> But is there some equivalent of pressing ctrl-C to make psql stop what 
> it is doing? For example, through the pipe stream I may execute a \i 
> command and the user wants to stop before the file is processed. What 
> mechanism is used to do this on win32? I thought it could be 
> accomplished on Unix with kill -2, hence my original question. But 
> maybe I'm looking in the wrong place.

Win32 doesn't have the granularity to do special signal numbers like we
do on Unix, so we have to map control-C to call a special libpq function
that communicates with the postmaster/backend to cancel the query.  No
way an outside process can do that.

Your only solution would be to hack psql to accept a signal somehow to
call that libpq function, and hack your client to send that signal to
psql somehow.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: sigint psql

From
"Magnus Hagander"
Date:
>> There is no way so signal *psql*, as in the client side process. The
>> signal emulation only runs in the server.
>>
>
>But is there some equivalent of pressing ctrl-C to make psql stop what
>it is doing? For example, through the pipe stream I may execute a \i
>command and the user wants to stop before the file is processed. What
>mechanism is used to do this on win32? I thought it could be
>accomplished on Unix with kill -2, hence my original question. But
>maybe I'm looking in the wrong place.

Take a look at GenerateConsoleCtrlEvent(). It can generate a fake
Ctrl-C. You'll need to figure out a console group etc, and I can't say
I've tested it, but it looks like a possible.

//Magnus