Re: Is there a way to tell how far along a COPY is in the process? - Mailing list pgsql-general

From andy
Subject Re: Is there a way to tell how far along a COPY is in the process?
Date
Msg-id 472F7868.8000401@squeakycode.net
Whole thread Raw
In response to Is there a way to tell how far along a COPY is in the process?  (Keaton Adams <kadams@mxlogic.com>)
List pgsql-general
Keaton Adams wrote:
>
> I’m looking for a way to see how many rows have been processed while a
> COPY is actually running.  I can’t seem to find a pg_stat table/view
> that will give me this level of visibility into the process.
>
> Is there any way to do this, to tell the number of rows processed during
> a COPY into a table while the COPY is still running?
>
> Thanks,
>
> Keaton

I use this little perl function:

sub runscript($)
{
    my $fname = pop;
    open(F, $fname) or die;
    print "executing $fname\n";
    my $sql = <F>;
    $db->do($sql) or die 'cant start copy';
    my $c = 0;
    while (<F>)
    {
        $db->pg_putline($_);
        if ($c % 10_000 == 0) {
            print "$c\r";
            if ($stop) { die; }
        }
        $c++;
    }
    print "$c total\n";
    $db->pg_endcopy;
    unlink($fname);
}


The first line in the file needs to be the sql copy command, like:

print F "copy junk(id, name, address) from stdin;\n";

The following lines are the data, like:

print F "$id\t$name\t$add\n";


-Andy

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Filter sequence
Next
From: Reg Me Please
Date:
Subject: Locale and indexes: howto?