Backend
home
📯

macOS PostgreSQL 설치

생성 일시
2025/03/08 14:44
태그
PostgreSQL
게시일
2025/03/08
최종 편집 일시
2025/04/08 13:27

PostgreSQL 설치하기

설치
$ brew install postgresql
Shell
복사
서비스 시작
$ brew services start postgresql
Shell
복사
psql 접속 및 데이터베이스 생성
$ psql postgres postgres=# CREATE DATABASE <databaseName>;
Shell
복사

사용자 확인

postgres=# \du
Shell
복사

사용자 생성

postgres라는 유저명, password를 'postgres'로 설정하여 유저 생성
세미콜론 입력하지 않으면 ‘CREATE ROLE’ 확인 안 됨!
postgres=# CREATE ROLE postgres WITH LOGIN PASSWORD 'postgres';
Shell
복사

사용자 권한 부여

postgres=# ALTER ROLE postgres CREATEDB; postgres=# ALTER ROLE postgres CREATEROLE;
Shell
복사
다시 유저를 확인해주면
postgres=# \du
Shell
복사

새로 만든 유저로 접속하기

postgres 유저로 접속
psql postgres -U postgres
Shell
복사
cmd 창을 보면 postgres =# 에서 postgres ⇒ 로 변한 것을 볼 수 있다.
# 은 superuser 이며 > superuser가 아니라는 뜻이다.

데이터베이스 생성

postgres=> CREATE DATABASE [데이터베이스명];
Shell
복사

특정 유저에게 DB의 모든 권한 부여하기

postgres=> GRANT ALL PRIVIELEGES ON DATABASE [데이터베이스명] TO [유저명];
Shell
복사
유저에게 DB 권한이 부여가 됨을 확인할 수 있다.

데이터베이스 리스트 보기

postgres=> \list
Shell
복사

특정 데이터베이스로 연결하기

postgres=> \connect [데이터베이스명];
Shell
복사

DBeaver 연동

우클릭 → create → Connection 클릭
PostgreSQL 아이콘 클릭
이전에 설정했던 username, password, Database를 입력해준다. 왼쪽 하단에 Test Connection 버튼을 클릭하여 잘 연동되는지 확인한다. Connected 라고 뜨면 연결 끝!

참고