macOS PostgreSQL 설치부터 접속까지 (DBeaver 로 접속)
macOS PostgreSQL 설치부터 접속까지
1. macOS에 PostgreSQL 설치부터 접속까지
설치환경
- macOS
- Homebrew 3.5.2
- postgresql 14.4
1.1 설치
$ brew install postgresql
1.2 PostgreSQL 설치확인
postgresql설치경로/bin/postgres --version
// postgres (PostgreSQL) 14.4
1.3 서비스 시작
$ brew services start postgresql
1.4 PostgreSQL 콘솔로 접속
$ psql postgres
postgres-# \du
List of roles
Role name | Attributes | Member of
-------------+------------------------------------------------------------+-----------
[사용자명] | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
1.5 사용자 생성
postgres=# CREATE ROLE postgres WITH LOGIN PASSWORD 'postgres';
CREATE ROLE
postgres=# \du
List of roles
Role name | Attributes | Member of
-------------+------------------------------------------------------------+-----------
[사용자명] | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres | | {}
1.6 사용자 권한 부여
postgres=# ALTER ROLE postgres CREATEDB;
ALTER ROLE
postgres=# ALTER ROLE postgres CREATEROLE;
ALTER ROLE
postgres=# \du
List of roles
Role name | Attributes | Member of
-------------+------------------------------------------------------------+-----------
[사용자명] | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres | Create role, Create DB | {}
1.7 사용자에게 데이터베이스 권한 부여
postgres=# CREATE DATABASE [데이터베이스명];
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE [데이터베이스명] TO postgres;
GRANT
1.8 데이터베이스 연결
postgres=# \connect [데이터베이스명];
You are now connected to database "[데이터베이스명]" as user "[사용자명]".
1.9 데이터베이스 확인
[데이터베이스명]=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+-------------+----------+---------+-------+-----------------------------
postgres | [사용자명] | UTF8 | C | C |
template0 | [사용자명] | UTF8 | C | C | =c/[사용자명] +
| | | | | [사용자명]=CTc/[사용자명]
template1 | [사용자명] | UTF8 | C | C | =c/[사용자명] +
| | | | | [사용자명]=CTc/[사용자명]
[데이터베이스명] | [사용자명] | UTF8 | C | C | =Tc/[사용자명] +
| | | | | [사용자명]=CTc/[사용자명]+
| | | | | postgres=CTc/[사용자명]
(4 rows)
1.10 생성한 사용자로 접속
psql [데이터베이스명] -U postgres
1.11 데이터베이스를 삭제할 경우 - 데이터베이스 소유주로 접속 필요함
postgres=#DROP DATABASE [데이터베이스명];
2. DB Tool 설치 (DBeaver 사용)
Download | DBeaver Community
Download Tested and verified for MS Windows, Linux and Mac OS X. Install: Windows installer – run installer executable. It will automatically upgrade version (if needed). MacOS DMG – just run it and drag-n-drop DBeaver into Applications. Debian package
dbeaver.io
2.1 좌측 탭에서 우클릭 - Create - Connection 을 클릭한다.
2.2 PostgreSQL 선택후, [다음] 버튼 클릭한다.
2.3 driver 파일이 자동으로 뜨고, [다운로드] 버튼을 클릭한다.
2.4 DB 연결 설정 정보 입력하기
위에서 생성한 Database 명을 입력하고, username : postgres / password : postgres 입력한다.
2.5 접속 완료 확인하기