1.配置PostgreSQL的yum倉庫源
1.1 檢查本地是否部署PostgreSQL
rpm -qa | grep postgres
1.2 配置鏡像源
rpm -Uvh https://mirrors.aliyun.com/postgresql/repos/yum/reporpms/
EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sed -i "s@https://download.postgresql.org/pub@https://mirrors.aliyun.com/
postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repo
yum clean cache
yum makecache
1.3 檢查yum倉庫鏡像源狀態(tài)
yum repolist all |grep enable
2.安裝PostgreSQL
2.1 安裝PostgreSQL
yum -y install postgresql13-server
2.2 初始化數(shù)據(jù)庫
[root@root ~]# postgresql-13-setup initdb
Initializing database ... OK
2.3 啟動(dòng)PostgreSQL數(shù)據(jù)庫
# 開機(jī)自啟動(dòng)
systemctl enable postgresql-13
# 啟動(dòng)數(shù)據(jù)庫
systemctl start postgresql-13
2.4 檢查PostgreSQL數(shù)據(jù)庫狀態(tài)
systemctl status postgresql-13.service
3.修改用戶密碼
3.1 切換postgres用戶
su - postgres
3.2 登錄PostgreSQL數(shù)據(jù)庫
[root@root ~]# su - postgres
Last login: Tue Jul 18 12:05:42 CST 2023 on pts/0
[postgres@root ~]$ psql -U postgres
psql (13.11)
Type "help" for help.
postgres=#
3.3 修改PostgreSQL數(shù)據(jù)庫用戶密碼
ALTER USER postgres WITH PASSWORD ‘123456’
4.配置PostgreSQL遠(yuǎn)程訪問
4.1 配置遠(yuǎn)程訪問
# 修改/var/lib/pgsql/13/data/postgresql.conf配置文件,開啟遠(yuǎn)程訪問重虑。
# 刪除localhost罚斗,改為監(jiān)聽所有,或者自己指定的服務(wù)器IP地址。
[postgres@root ~]$ grep listen /var/lib/pgsql/13/data/postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
# 修改/var/lib/pgsql/13/data/pg_hba.conf文件丧裁,新增以下兩行:
host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 trust
4.2 重啟PostgreSQL服務(wù)
systemctl restart postgresql-13.service
4.3 遠(yuǎn)程連接PostgreSQL數(shù)據(jù)庫
終端連接
D:\Program Files\Postgresql\bin>psql -hxx.xx.xx.xx -Upostgres -W
口令:
psql (11.2, 服務(wù)器 13.11)
輸入 "help" 來獲取幫助信息.
postgres=#
工具連接