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();
68 $refresh = 'SELECT refresh_materialized_phenotype_jsonb_table_concurrently()';
70 $refresh = 'SELECT refresh_materialized_phenotype_jsonb_table()';
73 $h = $dbh->prepare($refresh);
74 $status = $h->execute();
76 $q = "UPDATE public.matviews SET currently_refreshing=?";
78 $h = $dbh->prepare($q);
82 if ($opt_m eq 'stockprop'){
84 $refresh = 'SELECT refresh_materialized_stockprop_concurrently()';
86 $refresh = 'SELECT refresh_materialized_stockprop()';
89 my $h = $dbh->prepare($refresh);
90 $status = $h->execute();
93 print STDERR
"Materialized views refreshed! Status: $status" . localtime() . "\n";
100 print STDERR
"Done, exiting refresh_matviews.pl \n";