티스토리 뷰

데이터베이스/PostgreSQL

psql 명령어 몇가지...

메모하는습관 2022. 1. 19. 01:20

먼저 psql을 명령어를 사용하여 PostgreSQL에 접속 한다.

$ psql -U postgres -W
postgres 사용자의 암호: 
psql (10.17)
도움말을 보려면 "help"를 입력하십시오.

postgres=#

-U 옵션은 사용자이고 -W 옵션은 비번을 입력하겠다는 의미이다.

 

이제 psql에서 자주 사용하는 명령어 몇가지를 알아보자

 

데이터베이스 목록 조회 \l

좀더 자세한 내용을 원한다면 뒤에 + 만 더 붙이면 된다. \l+

postgres=# \l
                                 데이터베이스 목록
   이름    |  소유주   | 인코딩 |   Collate   |    Ctype    |      액세스 권한      
-----------+-----------+--------+-------------+-------------+-----------------------
 postgres  | postgres  | UTF8   | ko_KR.UTF-8 | ko_KR.UTF-8 | 
 template0 | postgres  | UTF8   | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres          +
           |           |        |             |             | postgres=CTc/postgres
 template1 | postgres  | UTF8   | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres          +
           |           |        |             |             | postgres=CTc/postgres           
(3개 행)

postgres=# \l+
                                                                     데이터베이스 목록
   이름    |  소유주   | 인코딩 |   Collate   |    Ctype    |      액세스 권한      |  크기   | 테이블스페이스 |                    설명                    
-----------+-----------+--------+-------------+-------------+-----------------------+---------+----------------+--------------------------------------------
  postgres | postgres  | UTF8   | ko_KR.UTF-8 | ko_KR.UTF-8 |                       | 7863 kB | pg_default     | default administrative connection database
 template0 | postgres  | UTF8   | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres          +| 7729 kB | pg_default     | unmodifiable empty database
           |           |        |             |             | postgres=CTc/postgres |         |                | 
 template1 | postgres  | UTF8   | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres          +| 7729 kB | pg_default     | default template for new databases
           |           |        |             |             | postgres=CTc/postgres |         |                | 
(3개 행)

 

데이터베이스 연결 \c 데이터베이스명

postgres=# \c postgres
암호: 
접속정보: 데이터베이스="postgres", 사용자="postgres".

 

테이블 목록 조회 \dt

좀더 자세한 내용을 원한다면 뒤에 + 만 더 붙이면 된다. \dt+

postgres=# \dt
         릴레이션(relation) 목록
 스키마 |   이름   |  종류  |  소유주   
--------+----------+--------+-----------
 public | table_01 | 테이블 | postgres
 public | table_02 | 테이블 | postgres
(2개 행)

postgres=# \dt+
                 릴레이션(relation) 목록
 스키마 |   이름    |  종류  |  소유주   |    크기    | 설명 
--------+---------- +--------+-----------+------------+------
 public | table_01  | 테이블 | postgres  | 8192 bytes | 
 public | table_02  | 테이블 | postgres  | 40 kB      | 
(2개 행)
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday