Skip to content

Psql

PostgreSQL의 명령행 클라이언트.

How to install

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

Command line example

query 파일의 쿼리를 실행하여 result 파일에 저장 한다.

psql -d recc -U recc -W -h ec2-13-125-229-118.ap-northeast-2.compute.amazonaws.com -p 5432 -f query -o result
  • -d recc: 데이터 베이스 이름
  • -U recc: 데이터 베이스 이름
  • -W: 비밀번호를 입력한다.
  • -h ec2-13-125-229-118.ap-northeast-2.compute.amazonaws.com: 호스트 주소
  • -p 5432: 포트 번호
  • -f query: 실행할 쿼리가 적혀있는 파일
  • -o result: 쿼리 실행 결과를 입력할 파일

로컬 호스트 접속:

psql -d recc -U recc -W -h localhost -p 5432

Command examples

\dt
List of tables
다음과 같이 출력됨:
recc-# \dt
              List of relations
 Schema |        Name         | Type  | Owner
--------+---------------------+-------+-------
 public | a4y_chart_days      | table | recc
 public | a4y_chart_hours     | table | recc
 public | a4y_device          | table | recc
 public | a4y_service         | table | recc
 public | a4y_state_last      | table | recc
 public | recc_daemon         | table | recc
 public | recc_group          | table | recc
 public | recc_group_member   | table | recc
 public | recc_info           | table | recc
 public | recc_layout         | table | recc
 public | recc_permission     | table | recc
 public | recc_port           | table | recc
 public | recc_project        | table | recc
 public | recc_project_member | table | recc
 public | recc_task           | table | recc
 public | recc_user           | table | recc
 public | recc_widget         | table | recc
(17 rows)
\dT
List of data types
다음과 같이 출력됨:
postgres=> \dT
               List of data types
   Schema   |        Name         | Description
------------+---------------------+-------------
 extensions | _time_trial_type    |
 extensions | embd                |
 public     | cluster_status      |
 public     | data_type           |
 public     | invoice_status      |
 public     | metric_code         |
 public     | metric_type         |
 public     | payment_provider    |
 public     | plan_code           |
 public     | reset_period        |
 public     | subscription_status |
(11 rows)
\dT+ public.meric_code
데이터 타입의 Item 목록 조회
다음과 같이 출력됨:
postgres=> \dT+ public.meric_code
                                    List of data types
 Schema | Name | Internal name | Size | Elements | Owner | Access privileges | Description
--------+------+---------------+------+----------+-------+-------------------+-------------
(0 rows)

See also

Favorite site