Re: persistant psql feature suggestion - Mailing list pgsql-hackers

From Andrew Dunstan
Subject Re: persistant psql feature suggestion
Date
Msg-id 002001c33e49$eb8c96e0$6401a8c0@DUNSLANE
Whole thread Raw
In response to persistant psql feature suggestion  (James Pye <jwp@rhid.com>)
Responses Re: persistant psql feature suggestion
List pgsql-hackers
OK, worked out the wrinkle. psql is behaving perfectly well, but the shim
doesn't get a SIGPIPE until it tries to write to it after psql has exited.

A slightly hackish fix for this would be to put this line after the "print
$_" line:
 if ($_ eq "\\q\n") { sleep 1; print " "; } # get SIGPIPE if client gone

cheers

andrew


----- Original Message ----- 
From: "Andrew Dunstan" <andrew@dunslane.net>
To: "Matthew T. O'Connor" <matthew@zeut.net>; "James Pye" <jwp@rhid.com>
Cc: <pgsql-hackers@postgresql.org>
Sent: Saturday, June 28, 2003 5:44 PM
Subject: Re: [HACKERS] persistant psql feature suggestion


> Another way is to put a little shim between the fifo and psql. Here's one
I
> quickly whipped up in perl (code stolen shamelessly from the perl man
> pages). To run in background, invoke thus
>   ( perl myperlfile myfifo | psql gatabase ) &
>
> The only wrinkle I found was that I had to send the \q twice to make it
> quit - I have no idea why.
> andrew
>
> ------------------------------
> use strict;
>
> my $curpos;
> my $fifofile = shift || usage();
>
> $|=1;
>
> open(FILE,$fifofile) || die $!;
> for (;;)
>   {
>     for ($curpos = tell(FILE); $_ = <FILE>; $curpos = tell(FILE))
>       {
>          print $_;
>       }
>     sleep(1);
>     seek(FILE, $curpos, 0);
>   }
>
>
> sub usage
>   {
>     print STDERR "usage: ",$0," fifofile\n";
>     exit 1;
>   }
>
> ----- Original Message ----- 
> From: "Matthew T. O'Connor" <matthew@zeut.net>
> To: "James Pye" <jwp@rhid.com>
> Cc: <pgsql-hackers@postgresql.org>
> Sent: Friday, June 27, 2003 1:44 PM
> Subject: Re: [HACKERS] persistant psql feature suggestion
>
>
> > On Fri, 2003-06-27 at 03:21, James Pye wrote:
> > > Greets,
> > >
> > > Just a thought for a psql enhancement, afiak, it is not easily
possible
> for persistent connections to a database in a shell script..
> > > The ability for psql to remain in the background reading from stdin
and
> writing to stdout until explicitly killed. More specifically, so a shell
> scriptor can have "persistent" connections to the database by calling psql
> once(leaving it in the bg), and redirecting stdio through a
> fifo(mkfifo)(sending queries by echo > fifo, and fetching results by cat
> fifo).
> > > When I have tried this in the past it will read the query, execute it,
> and exit when the results are cat'd from the fifo.
> >
> > Not sure if it's exactly what you are looking for, nor how well it's
> > still maintained, but....
> >
> > I believe there is a took out there called pgbash which is a modified
> > version of bash that understands database queries natively.  I think
> > it's just what you are looking for.
> >
> > Check out:  http://www.psn.co.jp/PostgreSQL/pgbash/index-e.html
> >
> > Looks like it was updated for 7.3
> >
> > Matthew
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster



pgsql-hackers by date:

Previous
From: "Shridhar Daithankar"
Date:
Subject: Re: Urgent : Regarding Submission of Code
Next
From: Bruno Wolff III
Date:
Subject: Re: Week numbers and years