[튜토리얼] PostgreSQL 시작

NuyHes·2025년 3월 23일
0

튜토리얼

목록 보기
22/26
post-thumbnail

SpringBoot 프로젝트에서 DB를 연결하기 위해 글을 작성한다.

PostgreSQL 설치 후 기본 셋팅

1. psql 명령어가 안되는 경우

설치 후 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

윈도우의 환경변수에 추가를 한다.

  1. 윈도우 검색 - 시스템 환경 변수 편집 클릭

  2. 환경 변수(N) 클릭

  3. 시스템 변수(S)의 Path 편집 클릭

  4. 새로 만들기를 해서 PostgreSQL이 설치된 경로를 넣어준다.

  5. 보통 C:\Program Files\PostgreSQL\버전\bin 에 위치한다.


2. PowerShell에서 PostgreSQL 접속하기

1. psql -U postgres 로 접속

# powerShell 

psql -U postgres

그래도 안될 경우에는

# powerShell

 & "C:\Program Files\PostgreSQL\17\bin\psql.exe" -U postgres

해당 설치된 bin 폴더 내부 psql.exe 경로까지 써주고 -U postgres를 입력한다.

2. postgres 사용자의 암호:

해당 사용자 암호를 요구한다. postgreSQL 설치할 때 설정한 암호 입력한다.

3. DB생성

CREATE DATABASE <db명>; 입력 후 엔터

4. 해당 만든 DB에 접속

\c <db명>

5. 전체 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개 행)

0개의 댓글