在CentOS7上安装PostgreSQL的方法

安装

安装PostgreSQL服务器。

インストール実行

terminal
yum -y install postgresql-server

起始设置

数据库初始化

初期化コマンドを実行。/var/lib/pgsql/dataに設定ファイルなどが配置される。

terminal
postgresql-setup initdb

编辑postgresql.conf

orgファイルバックアップ & 編集

terminal
cd /var/lib/pgsql/data
cp postgresql.conf postgresql.conf.org
echo “listen_addresses = ‘*'” >> /var/lib/pgsql/data/postgresql.conf

差分確認

terminal
diff -u postgresql.conf.org postgresql.conf

— postgresql.conf.org 2017-01-16 16:57:24.904920137 +0900
+++ postgresql.conf 2017-01-16 17:00:13.670101306 +0900
@@ -575,3 +575,4 @@
#——————————————————————————

# Add settings for extensions here
+listen_addresses = ‘*’

编辑pg_hba.conf文件。

orgファイルバックアップ & 編集

terminal
cd /var/lib/pgsql/data
cp pg_hba.conf pg_hba.conf.org

echo “# PostgreSQL Client Authentication Configuration File” > ./pg_hba.conf
echo “# ===================================================” >> ./pg_hba.conf
echo “local all all trust” >> ./pg_hba.conf
echo “host all all 127.0.0.1/32 trust” >> ./pg_hba.conf
echo “host all all ::1/128 trust” >> ./pg_hba.conf

確認 (orgはコメントだらけでdiff取ると長くなるので、変更後の内容のみ)

terminal
cat pg_hba.conf

# PostgreSQL Client Authentication Configuration File
# ===================================================
local all all trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust

开机

启动PostgreSQL

起動コマンド実行

terminal
service postgresql restart

确认连接

确认能够连接到PostgreSQL

local接続の可否を確認

terminal
psql -U postgres -h 127.0.0.1 -w

psql (9.2.18)
“help” でヘルプを表示します.

postgres=#

更改postgres用户的密码

SQLを実行

terminal
psql -U postgres -c “ALTER ROLE postgres WITH PASSWORD ‘your-secure-password'”

ALTER ROLE

创建数据库

SQLを実行

terminal
psql -U postgres -W -c “CREATE DATABASE your_database_name”;
ユーザ postgres のパスワード:

CREATE DATABASE

广告
将在 10 秒后关闭
bannerAds