Introduction
ずっとMySQL
ばかりしか使っておらず、初めて PostgreSQL
を触りはじめてみたので
備忘録としてまとめを記載
環境
Date: 2020/02/25
OS : macOS Catalina (10.15.3)
インストール方法
Homebrew
本手順は Homebrew
を使ってインストールを行います。
※もしまだの方は参考文献をご参照ください
$ brew install postgresql
初期化
$ initdb /usr/local/var/postgres -E utf8
導入時にもし下記のような文がでるなら、/usr/local/var/
配下にあるpostgresql
ディレクトリを削除して、もう一度同じコマンドを入力してみましょう
initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".
バージョン
$ postgres --version
postgres (PostgreSQL) 12.1
起動
$ pg_ctl -D /usr/local/var/postgres -l logfile start
一覧
$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | username | UTF8 | C | C |
template0 | username | UTF8 | C | C | =c/username +
| | | | | username=CTc/username
template1 | username | UTF8 | C | C | =c/username +
| | | | | username=CTc/username
(3 rows)
接続
$ psql -U username postgres
psql (12.1)
Type "help" for help.
postgres=#
postgres=#