LoginSignup
0
0

More than 3 years have passed since last update.

HerokuでPostgreSQLにリモートログインをするためのメモ書き

Last updated at Posted at 2020-04-22

概要

Heroku Postgresにターミナルから接続する際のメモ書きを書いてみました。

あくまで、メモ書きなので説明不足・内部的に何が行われているかは本家の文献や他の方の記事をお読みください。
特にこのあたりをお読みください

前提

以下が前提になっています。

  • 著者が試しているPCは Mac OS 10.14.6
  • PC(Mac)上に psql が設定済み
  • Herokuのアプリケーションが作成済み、HerokuのPostgreSQLが設定ずみ
  • サーバプログラムからHerokuのPostgreデータベースにテーブル・データが追加済み

コマンド

今回はHerokuアプリの設定を以下を想定して説明をおこなう。

  • アプリケーション名を testapp
  • リモートブランチ名を stg
  • Herokuで紐づけているデータベースの名前を testdb
  • データベース内に存在するテーブルは1個で testtable

Herokuのアプリケーションのディレクトリに移動

cd /path/to/testapp

Heroku Postgresに接続(--remote指定も行えます)

heroku ps:psql --remote stg

こんな質問が聞かれるので、yで返す

 ›   Warning: ps:psql is not a heroku command.
Did you mean pg:psql? [y/n]:y

shellがこんな感じの表示になっていたらOK(~~は環境ごとに異なる)

--> Connecting to postgresql-~~
psql (~~)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

testdb::DATABASE=>

Postgreのコマンドを試す

テーブル一覧を出力する(\t)

testdb::DATABASE=> \t

テーブル内のデータを全て出力する(select * from ~)

testdb::DATABASE=> select * from "testtable";

Heroku Postgres との接続を切る(\q)

testdb::DATABASE=> \q

参考文献

Heroku
Heroku Postgres
Heroku Dev Center Documentation
【PostgreSQL チュートリアル】Macへのインストール方法と基本コマンド
[PostgreSQL] よく使うコマンドまとめ
Swift Vapor + Heroku で 本番環境やステージング環境を分けて用意できるようになる

0
0
0

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
0
0