LoginSignup
8

More than 5 years have passed since last update.

MacからRedshiftにpsqlで接続する

Last updated at Posted at 2016-03-25

PostgreSQLをインストール

$ brew install postgresql
$ postgres --version
postgres (PostgreSQL) 9.4.4

psqlで接続

$ psql "host=[host] user=[user] dbname=[dbname] port=[port]"
Password:

パスワードを聞かれるのが面倒な方は以下のワンライナーで。

$ PGPASSWORD=[password] psql -h [Endpoint] -U [username] -d [dbname] -p [port]

接続してしまえば、自由にSQLを叩くことが出来ます。

psqlのコマンド

psqlコマンドが用意されています。

コマンド一覧を見る

基本的に困れば、これで確認できます。

dbname=> \?

psqlの接続解除

dbname=> \q

DB一覧を確認

dbname=> \l

テーブル一覧を確認

dbname=> \d

カラムの確認

dbname=> \d [table]

tableの指定方法はschema.name

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8