11 my ($mdbh, $sdbh, $table) = @_;
12 my $start = [ Time::HiRes::gettimeofday ];
13 my $data = $mdbh->selectall_arrayref("SELECT * FROM $table");
14 my $elapsed = Time::HiRes::tv_interval($start);
15 #printf "MySQL $table time used: $elapsed\n";
17 $start = [ Time::HiRes::gettimeofday ];
18 $sdbh->do("DELETE FROM $table");
19 $sdbh->do("COPY $table FROM STDIN");
21 for my $row (@$data) {
22 $sdbh->pg_putcopydata(join("\t", map { Encode::decode('iso8859-1', $_ // '\N') } (@$row)) . "\n");
24 $sdbh->pg_putcopyend();
25 $elapsed = Time::HiRes::tv_interval($start);
26 #printf "PostgreSQL $table time used: $elapsed\n";
29 my $mdbh = DBI->connect($config::master_connstr, $config::master_username, $config::master_password)
30 or die "PostgreSQL connect: " . $DBI::errstr;
31 $mdbh->{AutoCommit} = 0;
32 $mdbh->{RaiseError} = 1;
34 my $sdbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password)
35 or die "PostgreSQL connect: " . $DBI::errstr;
36 $sdbh->{AutoCommit} = 0;
37 $sdbh->{RaiseError} = 1;
39 sync_table($mdbh, $sdbh, "Fotballbrukere");
40 sync_table($mdbh, $sdbh, "Fotballdeltagere");
41 sync_table($mdbh, $sdbh, "Fotballresultater");
42 sync_table($mdbh, $sdbh, "Fotballserier");