3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7にpostgresql9.6をセットアップ

Posted at

#参考
CentOSにPostgreSQL9.5をインストールおよびテスト

#Vagrantの場合

ポートフォワード
config.vm.network "forwarded_port", guest: 5432, host: 50432, id:"postgres"
スクリプト
config.vm.provision "shell", inline: <<-SHELL

sudo yum -y install yum-plugin-priorities

#日本語化
 sudo yum -y install ImageMagick ImageMagick-devel ipa-pgothic-fonts ibus-kkc vlgothic-*
 sudo localectl set-locale LANG=ja_JP.UTF-8
 sudo source /etc/locale.conf 
 sudo timedatectl set-timezone Asia/Tokyo

#gitのインストール
yum -y install git

#firewalldでHTTPを許可
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

#postgresql
wget https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-1.noarch.rpm
sudo rpm -ivh pgdg-centos96-9.6-1.noarch.rpm

sudo yum update
sudo yum -y install postgresql96*

sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb

sudo systemctl start postgresql-9.6
sudo systemctl enable postgresql-9.6

sudo cp /vagrants/p* /var/lib/pgsql/9.6/data/

sudo systemctl restart postgresql-9.6

sudo firewall-cmd --permanent --zone=public --add-service=postgresql
sudo systemctl restart firewalld.service

SHELL

#最新のリポジトリをインストール

https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-1.noarch.rpm

sudo rpm -ivh pgdg-centos96-9.6-1.noarch.rpm
念のためのupdate
sudo yum update

#postgresqlをインストール

sudo yum -y install postgresql96*

初期化
/usr/pgsql-9.6/bin/postgresql96-setup initdb

起動
systemctl start postgresql-9.6

サービスに登録
systemctl enable postgresql-9.6


#設定ファイルを編集

vi /var/lib/pgsql/9.6/data/postgresql.conf

postgresql.conf
59行目
# listen_addresses = 'localhost' 
↓
listen_addresses = '*' 

419行目
log_line_prefix = '< %m >'
↓
log_line_prefix = '<%t %u %d>'

vi /var/lib/pgsql/9.6/data/pg_hba.conf

postgresql.conf
# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
# IPv6 local connections:
host    all         all         ::1/128               trust

##変更後の再起動
systemctl restart postgresql-9.6


#スーパユーザのパスワード変更

su - postgres
psql
postgres=# \password postgres
新しいパスワード: 
もう一度入力してください:
postgres=# \q

firewall-cmd --permanent --zone=public --add-service=postgresql

systemctl restart firewalld.service


#sqlファイルの実行
psql -f ./sql_file.sql -U user_name -D db_name (-h ホスト名)

#コマンド

テーブル一覧取得
select relname as TABLE_NAME from pg_stat_user_tables;
テーブル削除
DROP TABLE tablename;
3
3
1

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?