SpringBoot 프로젝트에서 DB를 연결하기 위해 글을 작성한다.
설치 후 PowerShell에서 psql -U postgres를 쳤을 때 다음과 같은 오류가 발생한다면
# PowerShell
PS C:\WINDOWS\system32> psql -U postgres
psql : The term 'psql' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ psql -U postgres
+ ~~~~
+ CategoryInfo : ObjectNotFound: (psql:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
윈도우의 환경변수에 추가를 한다.
윈도우 검색 - 시스템 환경 변수 편집
클릭
환경 변수(N) 클릭
시스템 변수(S)의 Path
편집 클릭
새로 만들기를 해서 PostgreSQL이 설치된 경로를 넣어준다.
보통 C:\Program Files\PostgreSQL\버전\bin
에 위치한다.
# powerShell
psql -U postgres
그래도 안될 경우에는
# powerShell
& "C:\Program Files\PostgreSQL\17\bin\psql.exe" -U postgres
해당 설치된 bin 폴더 내부 psql.exe 경로까지 써주고 -U postgres를 입력한다.
해당 사용자 암호를 요구한다. postgreSQL 설치할 때 설정한 암호 입력한다.
CREATE DATABASE <db명>;
입력 후 엔터
\c <db명>
\l
해당 powerShell의 결과
postgres 사용자의 암호:
psql (17.4)
도움말을 보려면 "help"를 입력하십시오.
postgres=#
postgres=#
postgres=# CREATE DATABASE mydb;
CREATE DATABASE
postgres=# \c mydb
접속정보: 데이터베이스="mydb", 사용자="postgres".
mydb=# \l
데이터베이스 목록
이름 | 소유주 | 인코딩 | 로케일 제공자 | Collate | Ctype | 로케일 | ICU 룰 | 액세스 권한
-----------+----------+--------+---------------+---------+-------+--------+--------+-----------------------
mydb | postgres | UTF8 | libc | ko-KR | ko-KR | | |
postgres | postgres | UTF8 | libc | ko-KR | ko-KR | | |
template0 | postgres | UTF8 | libc | ko-KR | ko-KR | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | ko-KR | ko-KR | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4개 행)