Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Vacuum writes to STDERR so you can redirect & capture that. Here is a program based on an old node by davido (thanks! o/) (which was based on an example in perldoc perlfunc).

It drops/creates a dummy table t, and vacuums it, silently capturing the output (then dumping it in STDOUT):

use strict; use DBI; main(); exit; sub main { my $dbh = DBI->connect("dbi:Pg:", undef,undef, {RaiseError=>1,Prin +tError=>0}); my $table = "t"; $dbh->do("drop table $table") or die "die 1 - $!\n"; $dbh->do("create table t(c text)") or die "die 2 - $!\n"; my $routput = vacuum_analyze($dbh, $table); print "-- verbose output:\n"; print "-"x70, "\n"; print $$routput; print "-"x70, "\n"; } sub vacuum_analyze { my ($dbh, $table) = @_; my $output; open OLDERR, ">&STDERR"; close STDERR; open STDERR, ">", \$output or die "error opening a stderr (heh) +\n"; $dbh->do("vacuum verbose analyze $table"); close STDERR; open STDERR, ">&OLDERR"; \$output; }

Running that gives:

2012.12.18 12:47:31 aardvark@bulldog:~/pg_stuff/pg_sql/pgsql.HEAD [0] $ perl -- verbose output: ---------------------------------------------------------------------- INFO: vacuuming "public.t" INFO: "t": found 0 removable, 0 nonremovable row versions in 0 out of + 0 pages DETAIL: 0 dead row versions cannot be removed yet. There were 0 unused item pointers. 0 pages are entirely empty. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: vacuuming "pg_toast.pg_toast_28335219" INFO: index "pg_toast_28335219_index" now contains 0 row versions in +1 pages DETAIL: 0 index row versions were removed. 0 index pages have been deleted, 0 are currently reusable. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: "pg_toast_28335219": found 0 removable, 0 nonremovable row vers +ions in 0 out of 0 pages DETAIL: 0 dead row versions cannot be removed yet. There were 0 unused item pointers. 0 pages are entirely empty. CPU 0.00s/0.00u sec elapsed 0.00 sec. INFO: analyzing "public.t" INFO: "t": scanned 0 of 0 pages, containing 0 live rows and 0 dead ro +ws; 0 rows in sample, 0 estimated total rows ----------------------------------------------------------------------

(PostgreSQL 9.3devel, perl 5.16.2)

In reply to Re: Perl DBI postgres question (capturing STDERR from VACUUM) by erix
in thread Perl DBI postgres question by Anonymous Monk

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Eily]: Discipulus turn me into a Bishop
    Discipulus abracadabra.. Eily tranformed into a.. shop for bisexual peoples..
    [LanX]: Eily don't be sad ... you are the Bishop of our hearts.
    [marto]: 1nickt, I just said that in a Sean Connery accent
    [LanX]: Discipulus++ # Bi-Shop
    [Eily]: is the Bishop of hearts higher or lower ranked than the Jack?
    [ambrus]: Higher.
    [Eily]: Discipulus what's the merchandise? Other bi-people?
    [1nickt]: marto would like to hear that. Of course he speaks very deliberately and dramatically, allowing pauses between words, so if anybody could pull it off it would be him, or someone impersonating him ...
    [Eily]: Discipulus that's a chess joke BTW right? Because bishops don't walk straight :D

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (13)
    As of 2017-09-26 12:07 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (294 votes). Check out past polls.