title: PostgreSQL - REFRESH MATERIALIZED VIEW while pg_dump
body: <p>(Postgres version: 9.3)</p>
  
  <p>Asking this after searching around without any solution:</p>
  
  <ul>
  <li>I create a simple materialized view (in practice, I have a few of them).</li>
  </ul>
  
  <p><code>psql my_db -c "CREATE MATERIALIZED VIEW my_view AS (SELECT * FROM my_table);"</code></p>
  
  <ul>
  <li>I call pg_dump to backup the database.</li>
  </ul>
  
  <p><code>pg_dump -Fc my_db</code></p>
  
  <ul>
  <li>While pg_dump is running, I try to refresh the view using <code>REFRESH MATERIALIZED VIEW</code>.</li>
  </ul>
  
  <p><code>psql my_db -c "REFRESH MATERIALIZED VIEW my_view;"</code></p>
  
  <p>The <code>REFRESH</code> statement hangs (remains 'active') as long as pg_dump is active (this makes things even worse as while the view hangs on <code>REFRESH</code>, I cannot <code>SELECT</code> from it as well).
  My question is: how can I <code>REFRESH</code> materialized views while performing a dump?</p>
  
  <p>I don't mind excluding the data of the view from the dump if this will help, I don't need to save the data. But I <strong>do</strong> need to dump the view schema (<code>CREATE</code> statement).</p>
  
  <p>I have set-up a script to exclude all m.views from the dump, but it also excludes their schemas, and it complicates my dump command to an unreasonable amount just to make this work, so I'm looking for a simpler solution.</p>
  
  <p>Thanks in advance!</p>