LoginSignup
0
0

More than 3 years have passed since last update.

HomebrewでPostgreSQLをインストールして起動・停止する

Last updated at Posted at 2020-07-29

PostgreSQLをインストールする

用意するのもの
1. ターミナル(iTerm2)
2. Homebrew

Homebrewを使ってインストールしていきます。

最新バージョン

$ brew install postgresql

バージョンを指定する

$ brew search postgresql

で検索すると
postgresql postgresql@10 postgresql@11 postgresql@9.4 postgresql@9.5 postgresql@9.6
といった感じで表示されるので、@Version でバージョンを指定して

$ brew install postgresql@10

を実行してインストール完了!

確認

$ psql --version 

Command not found

Pathを通せばOKです。
Pathについての詳しいことは割愛します。

$ vi ~/.bash_profile

などでbash_profileを開いて、下記のようにPathを記載します。

export PATH=/usr/local/Cellar/postgresql@10/10.13_3/bin:$PATH

インストール時にバージョンを指定しなかった場合は、
@10 等のバージョンは不要です。
実際のパスはしっかり確認しましょう。

起動!

$ brew services start postgresql@10

インストール時にバージョンを指定しなかった場合は、
@10 等のバージョンは不要です。

データベース作成!

起動したまま、下記コマンドを実行する。

createdb <db_name>

停止!

$ brew services stop postgresql@10

まとめ

PostgreSQLを扱うのは初めてなので備忘録として。
PostgreSQLはこれから使い倒します。

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