コレグレーデギネード

WindowsとかUbuntuとかRubyとかRailsとか

Ubuntu16.04LTSにPostgreSQL(v9.5.5)をインストールする

PostgreSQLのインストール

$ sudo apt-get install posqgresql

postgresアカウントに切り替える

$ sudo su postgres
postgres@pc:/home/username$ 

通常のアカウントで使用できるようにユーザーを作成

postgres@pc:/home/username$ createuser --interactive
Enter name of role to add: username
Shall the new role be a superuser? (y/n) y

ユーザーの削除はdropuser

通常のアカウントからデータベース一覧を表示

$ psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 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
(3 rows)

データベース作成

$ createdb hello

データベースの確認

$ psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 hello     | username | UTF8     | ja_JP.UTF-8 | ja_JP.UTF-8 | 
 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)

データベースの削除はdropdb