Guest User

Untitled

a guest
Dec 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. 1) Create a linux user and set password
  2. sudo adduser read_access
  3.  
  4. .. then enter your password for this user
  5.  
  6. 2) Limit permission for the user (option)
  7. .. normally, this user only has root permission on it's directory. (/home/read_access)
  8.  
  9. 3) Set read-only role for this user to use Postgresql
  10.  
  11. psql -U postgres -d <your database>
  12.  
  13. CREATE USER read_access WITH PASSWORD '<your password>';
  14.  
  15. GRANT CONNECT ON DATABASE <your database> TO read_access;
  16.  
  17. GRANT SELECT ON ALL TABLES IN SCHEMA public TO read_access;
  18.  
  19. GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO read_access;
  20.  
  21. ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO read_access;
  22.  
  23. ALTER USER read_access SET default_transaction_read_only = on;
  24.  
  25. <br/>
  26. 4) Dump your database
  27. PGPASSWORD="<your password>" pg_dump -Fc --no-acl --no-owner -h localhost -U read_access -d <your database> -t <your table> > mydb.dump
  28.  
  29. 5) If you try to "change you will get this error"
  30. ERROR: cannot execute INSERT in a read-only transaction
Add Comment
Please, Sign In to add comment