5 refresh_matviews.pl - run PL/pgSQL functions to do a basic or concurrent refresh of all database materialized views
9 refresh_matviews.pl -H [database handle] -D [database name] -c [to run concurrent refresh] -m [materialized view select]
15 -c flag; if present, run concurrent refresh
16 -m materialized view select. can be either 'fullview' or 'stockprop'
18 All materialized views that are included in the refresh function will be refreshed
19 If -c is used, the refresh will be done concurrently, a process that takes longer than a standard refresh but that is completed without locking the views.
23 Bryan Ellerbrock <bje24@cornell.edu>
31 #use CXGN::DB::InsertDBH;
33 our ($opt_H, $opt_D, $opt_U, $opt_P, $opt_m, $opt_c, $refresh, $status);
34 getopts
('H:D:U:P:m:c');
36 print STDERR
"Connecting to database...\n";
37 my $dsn = 'dbi:Pg:database='.$opt_D.";host=".$opt_H.";port=5432";
38 my $dbh = DBI
->connect($dsn, $opt_U, $opt_P);
41 print STDERR
"Refreshing materialized views . . ." . localtime() . "\n";
43 if ($opt_m eq 'fullview'){
44 my $q = "UPDATE public.matviews SET currently_refreshing=?";
46 my $h = $dbh->prepare($q);
50 $refresh = 'SELECT refresh_materialized_views_concurrently()';
52 $refresh = 'SELECT refresh_materialized_views()';
55 $h = $dbh->prepare($refresh);
56 $status = $h->execute();
59 $refresh = 'SELECT refresh_materialized_stockprop_concurrently()';
61 $refresh = 'SELECT refresh_materialized_stockprop()';
64 $h = $dbh->prepare($refresh);
65 $status = $h->execute();
67 $q = "UPDATE public.matviews SET currently_refreshing=?";
69 $h = $dbh->prepare($q);
73 if ($opt_m eq 'stockprop'){
75 $refresh = 'SELECT refresh_materialized_stockprop_concurrently()';
77 $refresh = 'SELECT refresh_materialized_stockprop()';
80 my $h = $dbh->prepare($refresh);
81 $status = $h->execute();
84 print STDERR
"Materialized views refreshed! Status: $status" . localtime() . "\n";
91 print STDERR
"Done, exiting refresh_matviews.pl \n";