LoginSignup
2
2

More than 5 years have passed since last update.

UbuntuでPostgresqlをRails開発用に使えるように設定する

Last updated at Posted at 2015-10-25

私が使っているのはXubuntu15.10ですが多分Ubuntuでも同じです。

Install

% sudo apt-get install postgresql-server-dev-9.4 postgresql

SuperUserなロールの作成

% createuser hoge --superuser

hogeの部分は、Ubuntuで普段使っている自分のユーザー名と同じにします。

createdb

上記までを済ませると、普段使いのユーザーでDBの管理権限を得られます。
余談ですがUbuntuではPostgresqlをインストールするとinitdb済みの状態になっており、localeがUTF8になってます。
日本語のorder byとかおかしくなりますので、私はいつもRailsアプリではlocal=CでDBを作ってます。

% createdb --encoding=UTF8 --locale=C --template=template0 hoge

こうやって作るとこんな感じになります。

% psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 hoge      | hoge     | UTF8     | C           | C           | 
 postgres  | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
 template0 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)
2
2
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
2
2