본문 바로가기

공부기록/Data Engineering

[PostgreSQL] macOS에 PostgreSQL 설치 및 설정

반응형

설치

설치전 brew에 postgresql을 검색해본다.

brew search postgresql

 

기본 버전으로 설치를 시작한다.

brew install postgresql

 

서비스 시작

brew services start postgresql

 

postgres -V

 

설정

사용자 권한 계정 설정

먼저, postgre에 접속한다.

psql postgres

아래의 명령어로  role 리스트를 확인 할 수 있다. postgre는 설치시 자동으로 계정을 생성해준다.

postgres=# \du

 

권한을 설정해주기 전에, 기본으로 생성된 슈퍼유저의 비밀번호를 설정한다.

postgres=# \password postgres

 

데이터 베이스 생성

테스트 데이터 베이스를 생성해봅니다.

create database testdb;

 

데이터베이스 리스트 확인

\list

 

 

유저 생성

testuser라는 이름의 유저를 생성합니다.

create user testuser with encrypted password '1234';

 

 

권한 부여

testuser에게 데이터 베이스 생성 권한도 부여합니다.

alter user testuser createdb

 

 

testuser에게 testdb 데이터베이스에 대한 모든 권한을 부여합니다.

grant all privileges on database testdb to testuser;

 

계정 삭제

drop user [userid];

 

데이터베이스 연결 

\connect study

 

추가한 사용자로 접속해보기

psql testdb -U testuser

 

테이블 조회

\dt
반응형