title: How do I make a table read-only in PostgreSQL
body: <p>I need to prevent accidental changes in a core table of the application. I don't want anyone to change the rows during the operation of the application, though, I will make changes during the deployment of a new version of the application. For example:</p>
  
  <pre><code>create table procedure (
    id int primary key not null,
    name varchar(50) not null
  );
  
  insert into procedure (id, name) values (1, 'Send Exam Request');
  insert into procedure (id, name) values (2, 'Confirm Exam Data');
  insert into procedure (id, name) values (3, 'Close Visit');
  
  -- Now, make the table read-only.
  </code></pre>
  
  <p>Great, the first version of the application is now in production running well.</p>
  
  <p>Next month when I deploy the next version of the application:</p>
  
  <pre><code>-- Make the table read-write.
  
  insert into procedure (id, name) values (4, 'Request Visit'); -- new proc
  delete from procedure where id = 2; -- remove old unsupported proc
  
  -- Now, make the table read-only again.
  </code></pre>
  
  <p>Ideally, it would be great if an error message was shown if anyone tried to change it during normal operation of the application. Something like:</p>
  
  <pre><code>insert into procedure (id, name) values (5, 'New bad procedure');
  ERROR: Cannot modify table procedure. 
  Contact the system administrator if you want to make this change.
  </code></pre>
  
  <p>Any idea what's the best approach to make this happen?</p>