title: How does postgresql lock tables when inserting and selecting?
body: <p>I'm migrating data from one table to another in an environment where any long locks or downtime is not acceptable, in total about 80000 rows. Essentially the query boils down to this simple case:</p>
  
  <pre><code>INSERT INTO table_2
  SELECT * FROM table_1
  JOIN table_3 on table_1.id = table_3.id
  </code></pre>
  
  <p>All 3 tables are being read from and could have an insert at any time. I want to just run the query above, but I'm not sure how the locking works and whether the tables will be totally inaccessible during the operation. My understanding tells me that only the affected rows (newly inserted) will be locked. Table 1 is just being selected, so no harm, and concurrent inserts are safe so table 2 should be freely accessible.</p>
  
  <p>Is this understanding correct, and can I run this query in a production environment without fear? If it's not safe, what is the standard way to accomplish this?</p>