weblog

技術的なメモ置き場。

CentOS7 にPostgreSQL9.5をインストールする

ダウンロード

[vagrant@localhost ~]$ wget http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm

インストール

[vagrant@localhost ~]$ sudo rpm -ivh pgdg-centos95-9.5-2.noarch.rpm
[vagrant@localhost ~]$ sudo yum -y install postgresql95-server postgresql95-devel postgresql95-contrib

 

起動

[vagrant@localhost ~]$ sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
[vagrant@localhost ~]$ sudo systemctl start postgresql-9.5

 

システム起動時に自動起動させる

[vagrant@localhost ~]$ sudo systemctl enable postgresql-9.5

 

postgresユーザが追加されていることを確認

[vagrant@localhost ~]$ id postgres
uid=26(postgres) gid=26(postgres) groups=26(postgres)

 

postgresユーザに切り替え

[vagrant@localhost ~]$ sudo -i -u postgres

 

psqlの設定

-bash-4.2$ vi .psqlrc


.psqlrcに以下の内容を記載する

\set COMP_KEYWORD_CASE upper
\pset null (null)



COMP_KEYWORD_CASE upper ・・・ SQLキーワードを大文字で補完する
pset null (null) ・・・ nullのカラムに表示する内容

PostgreSQLに接続

-bash-4.2$ psql
拡張表示が自動的に使用されます
Null 表示は "(null)" です。
psql (9.5.3)
"help" でヘルプを表示します.

postgres=#




これで完了。


参考
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-centos-7
http://lets.postgresql.jp/documents/tutorial/centos/2
http://postd.cc/postgresql-on-the-command-line/