summary refs log tree commit diff
path: root/Cheat sheets/Postgresql.md
blob: 084ad71bee8464c37d63c72287a04b000899571a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
---
description: Create database, user and grant permissions
created: 2023-12-21
---

## Create database, and user for login

```bash
sudo -u postgres psql
```

```sql
CREATE DATABASE "database_name";
CREATE ROLE "username";
ALTER ROLE "username" WITH LOGIN;
ALTER USER "username" WITH PASSWORD 'change_me';
GRANT SELECT ON "table_name" TO "username";
```

> Replace `database_name`, `username`, `change_me` and `talbe_name`

## DB backup / restore