Search Postgresql Archives

Re: Is there a way to tell how far along a COPY is in the process?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
      message can get through to the mailing list cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux