LoginSignup
0
0

More than 5 years have passed since last update.

[自分用まとめ] postgresqlの使い方

Posted at

herokuのデータベースの中身をローカルでも再現したかったのですが、地味にリファレンスいろんなところ読まないといけなくて面倒だったのでまとめる。

まずはインストール

$ brew install postgres
# 以下省略

#ここらへん大事。初期設定の方法が載ってる。
To have launchd start postgresql at login:
    ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
    postgres -D /usr/local/var/postgres

パソコンの起動時に常にpostgresql起動しておきたいなら

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

postgresqlを明示的に起動したいなら

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

みたいな感じのをやる

操作方法

\hでヘルプ出てくるんでそこらへん見ればいいんですが、載ってないのだと

/d:テーブル一覧
\dn:データベースの確認
\l:データベース一覧

はよく使う。参考これはpsqlのコマンド。

herokuでdumpしたDBを復元

$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ユーザ名 -d データベース名 バックアップファイル名

でオーケー。

\connect database_name

で指定したデータベースと繋がるのであとは普通に操作。

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