Postgres - user 생성과 권한 추가 및 변경 방법
Postgres에서 처음 구성 시 user 생성과 권한 추가 및 변경하는 방법이다.
Postgres - user 생성과 권한 추가 및 변경 방법
Postgres 16
Container
CLI
개요
docker의 postgres내에서superuser가 생성하는 방법이다.host에서 package로 설치한 postgres 또한 동일하게 동작한다.
user 생성과 권한 추가 및 변경 방법
우선 container내의 psql을 통하여 DB에 접근한다.
접근 후 기존 user를 확인 후 필요 시 생성한다.
user 생성 후 login을 하려면 DB도 꼭 생성 해야한다.
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
37
38
39
40
41
42
43
44
45
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
# 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
# user DB 생성
postgres=# CREATE DATABASE deepadmin;
CREATE DATABASE
# DB 확인
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+------------+------------+--------+-----------+-----------------------
deepadmin | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
postgres | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
template0 | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4 rows)
This post is licensed under CC BY 4.0 by the author.