はじめに
CentOS6.6にPostgreSQL9.4をインストールする方法を記述します。
環境
- CentOS6.6
- PostgreSQL9.4
リポジトリの追加
$ wget http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm
$ sudo yum localinstall pgdg-centos94-9.4-1.noarch.rpm
インストール
$ sudo yum install postgresql94-server.x86_64 postgresql94.x86_64 postgresql94-libs.x86_64
データベースの初期化
$ sudo service postgresql-9.4 initdb
データベースを初期化中: [ OK ]
起動
$ sudo service postgresql-9.4 start
postgresql-9.4 サービスを開始中: [ OK ]
パスワード設定
$ sudo su - postgres
-bash-4.1$ psql
psql (9.4.4)
"help" でヘルプを表示します.
postgres=# alter user postgres with password '*****';
ALTER ROLE
postgres=# \q
ユーザ作成
-bash-4.1$ createuser -s admin
データベース作成
$ createdb sample;
$ psql -l
データベース一覧
名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権
-----------+----------+------------------+-------------+-------------------+-----------------------
postgres | postgres | UTF8 | ja_JP.UTF-8 | ja_JP.UTF-8 |
sample | admin | 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 行)
テーブル作成
$ psql sample
psql (9.4.4)
"help" でヘルプを表示します.
sample=# \d
リレーションがありません。
sample=# create table test(id integer, name character varying(32));
CREATE TABLE
sample=# \d
リレーションの一覧
スキーマ | 名前 | 型 | 所有者
----------+------+----------+---------
public | test | テーブル | vagrant
(1 行)
sample=# \d test
テーブル "public.test"
列 | 型 | 修飾語
------+-----------------------+--------
id | integer |
name | character varying(32) |