2020-04-28 17:29:52 +02:00
|
|
|
---
|
2021-09-13 00:48:07 +02:00
|
|
|
title: "Grant PostgreSQL read only access"
|
2020-04-28 17:29:52 +02:00
|
|
|
date: 2015-11-24
|
2021-09-13 00:48:07 +02:00
|
|
|
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 :
|
2023-04-23 22:33:49 +02:00
|
|
|
```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";
|
2023-04-23 22:33:49 +02:00
|
|
|
```
|