CentOS release 6.9 (Final) 64bit
# yum -y localinstall https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
※PostgreSQLが提供するyumリポジトリは、下記で確認できる。
https://yum.postgresql.org/repopackages.php
下記コマンドを実行して、利用できるソフトウェアを確認する。
# yum list postgres*
# yum -y install postgresql96-server.x86_64
# su - postgres
$ /usr/pgsql-9.6/bin/initdb -E UTF-8 --no-locale -D /var/lib/pgsql/9.6/data
$ exit
# service postgresql-9.6 start
# service postgresql-9.6 stop
※停止は、必要な場合に実施すること。
下記コマンドで、デフォルトで起動するようにする。
# chkconfig postgresql-9.6 on
# su - postgres
$ psql
postgres=# ALTER USER postgres PASSWORD 'new_password';
postgres=# \q
$ exit
# vi /var/lib/pgsql/9.6/data/postgresql.conf
--------------------------------
listen_addresses = '*'
--------------------------------
59行目を 'localhost' -> '*' に変更し、他ホストからの接続を許可する。
# vi /var/lib/pgsql/9.6/data/pg_hba.conf
<変更前>
--------------------------------
local all all trust
--------------------------------
<変更後>
--------------------------------
local all all md5
--------------------------------
# service postgresql-9.6 restart
# su - postgres
$ psql
パスワード:
psql (9.6.5)
→ログインできることを確認する。
$ createuser -P testuser
・DBの追加
$ psql
postgres=# create database testdb;
CREATE DATABASE
・DB所有者の変更
postgres=# ALTER DATABASE testdb OWNER TO testuser;
postgres=# \q
$ psql -d testdb -U testuser
testdb=> create table test (id int, name text);
CREATE TABLE
testdb=> \d
リレーションの一覧
スキーマ | 名前 | 型 | 所有者
----------+------+----------+----------
public | test | テーブル | testuser
(1 行)
testdb=> insert into test(id, name) values(1, 'テスト');
testdb=> select * from test;
→ testテーブルにデータの挿入と検索ができる。