Psql
lastmod 2026-02-24created 2021-11-1510 edits
Command-line client for PostgreSQL.
How to install
Command line example
Runs the queries in the query file and saves the output to the result file.
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: database name -
-U recc: database name -
-W: prompt for the password. -
-h ec2-13-125-229-118.ap-northeast-2.compute.amazonaws.com: host address -
-p 5432: port number -
-f query: file containing the queries to run -
-o result: file to write the query results to
Connecting to localhost:
Command examples
-
\dt - List of tables
- Output looks like this:
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
- Output looks like this:
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 - Show the list of Items of a data type
- Output looks like this:
postgres=> \dT+ public.meric_code
List of data types
Schema | Name | Internal name | Size | Elements | Owner | Access privileges | Description
--------+------+---------------+------+----------+-------+-------------------+-------------
(0 rows)