title: Refresh materialized views with concurrency
body: <p>I have a PostgreSQL DB, where I use materialized views. 
  The problem occurs when I try to refresh these materialized views. </p>
  
  <pre><code>REFRESH MATERIALIZED VIEW product_cat_mview;
  REFRESH MATERIALIZED VIEW productsforproject;
  </code></pre>
  
  <p>My solution is, when the user want to see updated data, he should click a "refresh button" on the web page, but this takes about 50s (on a local connection and about 2 minutes from the application server) and all this time the user has to wait, which is not good.</p>
  
  <p>Now I should create a solution to automatically refresh these materialized views every 10 minutes.
  I have created a Java solution with multithreading. But I have one problem.</p>
  
  <p>The first query</p>
  
  <pre><code>REFRESH MATERIALIZED VIEW CONCURRENTLY product_cat_mview;
  </code></pre>
  
  <p>works correct, but the second</p>
  
  <pre><code>REFRESH MATERIALIZED VIEW CONCURRENTLY productsforproject;
  </code></pre>
  
  <p>complains that I need to create a unique index. I tried create index, unique index etc. that I found in google, but I still get the message to "Create unique index".</p>