Post

Postgres - user 생성과 권한 추가 및 변경 방법

Postgres에서 처음 구성 시 user 생성과 권한 추가 및 변경하는 방법이다.

Postgres - user 생성과 권한 추가 및 변경 방법

Postgres 16

Container

CLI

개요


  • docker의 postgres내에서 superuser가 생성하는 방법이다.
  • host에서 package로 설치한 postgres 또한 동일하게 동작한다.

user 생성과 권한 추가 및 변경 방법


우선 container내의 psql을 통하여 DB에 접근한다.
접근 후 기존 user를 확인 후 필요 시 생성한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
dor1@hq-is-lxc-rdb:~$ docker exec -it postgres psql -U postgres
psql (16.0 (Debian 16.0-1.pgdg120+1))
Type "help" for help.

postgres=# \

# 기존 user 확인
postgres=# \du
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS

# user 생성
postgres=# CREATE USER deepadmin WITH PASSWORD 'qwer4321!';
CREATE ROLE

# user 확인
postgres=# \du
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 deepadmin |
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS

# role 추가(변경 또한 가능)
postgres=# ALTER ROLE deepadmin SUPERUSER CREATEROLE CREATEDB REPLICATION BYPASSRLS;
ALTER ROLE

# 확인
postgres=# \du
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 deepadmin | Superuser, Create role, Create DB, Replication, Bypass RLS
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS
This post is licensed under CC BY 4.0 by the author.