www/content/blog/miscellaneous/postgresql-read-only.md

19 lines
507 B
Markdown
Raw Normal View History

2020-04-28 17:29:52 +02:00
---
title: "Grant PostgreSQL read only access"
2020-04-28 17:29:52 +02:00
date: 2015-11-24
description: How to grant read only access to a PostgreSQL user
2021-03-12 18:12:41 +01:00
tags:
- PostgreSQL
2020-04-28 17:29:52 +02:00
---
2021-03-12 18:12:41 +01:00
## The solution
Here is the bare minimum a user need in order to have complete read only access on a postgresql database :
```sh
2020-04-28 17:29:52 +02:00
GRANT CONNECT ON DATABASE "db" TO "user";
\c db
GRANT USAGE ON SCHEMA public TO "user";
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "user";
2021-03-12 18:12:41 +01:00
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO "user";
```