1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[備忘録] postgresql [工事中]

Last updated at Posted at 2018-01-01

postgresql - mac

インストールとか

とりあえずこの流れでインストールまで行く。
$ brew list
$ brew update
$ brew search postgresql
$ brew install postgresql
インストール後のターミナルの結果(格納先)
〜〜〜略
🍺  /usr/local/Cellar/postgresql/10.1: 3,372 files, 38.8MB

install後の色々な確認

$ psql --version
psql (PostgreSQL) 10.1

$ which postgres  
/usr/local/bin/postgres

文字コードにUTF-8を指定してDBを初期化(エラーに見えるけど問題なし)

CMD
$ initdb /usr/local/var/postgres -E utf8
OUTPUT
The files belonging to this database system will be owned by user "{ユーザー名}". 
This user must also own the server process.

The database cluster will be initialized with locale "ja_JP.UTF-8". ★
initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8" ★
The default text search configuration will be set to "simple".

Data page checksums are disabled.

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".

起動

CMD
$ brew services start postgresql
OUTPUT
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 0), reused 9 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
Checking connectivity... done.
Tapped 0 formulae (42 files, 55.2KB)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

DB一覧の取得(初期化後のDBクラスタには3つのDBが存在)

CMD
$ psql -l
OUTPUT
                                        List of databases
   Name    |    Owner     | Encoding |   Collate   |    Ctype    |       Access privileges       
-----------+--------------+----------+-------------+-------------+-------------------------------
 postgres  |  {user name} | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
 template0 |  {user name} | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/{user name}              +
           |              |          |             |             | {user name}=CTc/{user name}
 template1 |  {user name} | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/{user name}              +
           |              |          |             |             | {user name}=CTc/{user name}
(3 rows)

DB作成

$ createdb test

DB接続

psql test

DBへの接続

$ psql test
psql (10.1)
Type "help" for help.

test=# 
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?