LoginSignup
13
12

More than 3 years have passed since last update.

macOS MojaveにpostgreSQLをインストールして設定まで

Last updated at Posted at 2019-03-30

postgreSQLをwindows環境下で勉強していたのですが、macにも導入する必要が発生したのでその際の試行錯誤を記録。
windows環境では下記の本を参考に導入しました。
【参考元】SQL 第2版 ゼロからはじめるデータベース操作

環境

  • macOS Mojave 10.14.2
  • postgreSQL 11.2

postgreSQLのインストール

ターミナルを起動してコマンド入力

$ brew install postgresql

インストール先
/usr/local/var/postgres

ロケールを変更

$ initdb /usr/local/var/postgres --locale ja_JP.UTF-8

インストールできているかバージョン確認してみる

$ postgres --version
postgres (PostgreSQL) 11.2

設定ファイルの書き換え

ローカルマシンからのみpostgreSQLに接続可能な設定にしておきます。
まずフォルダへ移動

$ cd /usr/local/var/postgres

設定ファイルを開きます。vimはまだ使いこなせないのでnanoを使用。

$ nano postgresql.conf

エディタが開くので
#listen_addresses = 'localhost'
とコメントアウトされている一文の#を削除
→ listen_addresses = 'localhost'

後々データーベース接続ソフトを使用したいので、portも設定しておきます。

#port = 5432
とコメントアウトされている一文の#を削除
→ port = 5432

postgreSQLサーバーを起動

$ postgres -D /usr/local/var/postgres

※ 終了するには control+c

postgreSQLへの接続(ログイン)

先程起動したサーバーとは別画面でターミナルを起動して接続

$ psql -d postgres
psql (11.2)
Type "help" for help.

postgres=# 

完了!


参考にさせて頂いた記事

13
12
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
13
12