postgresql commands

SQL Shell (psql) 에서 명령
postgreql 처음 써보는 데 사용한 명령어 및 커넥션 설정 정리

psql

psql commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- 데이터베이스 생성
CREATE DATABASE student;

-- 유저 생성
CREATE USER sung WITH PASSWORD '1234';

-- 권한 부여
GRANT ALL PRIVILEGES ON DATABASE student TO sung;

-- 특정 유저로 데이터베이스 접속
\c student sung

-- 데이터베이스 목록 보기
\l

-- 테이블 목록 보기
\d
\dt

-- 테이블 칼럼 보기
\d "User"

-- select query
-- 릴레이션을 못 찾았다고 하면 테이블명에 따옴표 붙이기
select * from "User";
  • 대소문자 구분은 안 해도 된다

connection

application.properties
1
2
3
4
5
6
7
spring.datasource.url=jdbc:postgresql://localhost:5432/student
spring.datasource.username=sung
spring.datasource.password=1234
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.format_sql=true

jdbc

pgAdmin

  • GUI로 DBMS 다루기

참고

Author

chinsung

Posted on

2021-07-28

Updated on

2021-08-28

Licensed under

댓글