UGA Boxxx

つぶやきの延長のつもりで、知ったこと思ったこと書いてます

【PostgreSQL】psqlを使ったPostgreSQLへの接続

コマンドラインベースで利用できる psql を利用してPostgreSQLに接続した作業メモ

以下のコマンドで接続する

$ psql "host=<HOST_NAME> port=5432 dbname=<DB_NAME> user=<USER_NAME> password=<PASSWORD>"

オプションの一覧を表示

$ postgres => \?

使用可能なデータベース一覧を表示

$ postgres => \l
                                                 List of databases
      Name       |       Owner       | Encoding |  Collate   |   Ctype    |            Access privileges
-----------------+-------------------+----------+------------+------------+-----------------------------------------
 mydb            | cloudsqlsuperuser | UTF8     | en_US.UTF8 | en_US.UTF8 |
 postgres        | cloudsqlsuperuser | UTF8     | en_US.UTF8 | en_US.UTF8 |

テーブルの一覧を表示

$ postgres => \d
                    List of relations
 Schema |         Name          | Type  |      Owner
--------+-----------------------+-------+-----------------
 public | my_table              | table | mydb

参考

https://www.dbonline.jp/postgresql/connect/index1.html#section1