Linux系統(tǒng)之安裝PostgreSQL數(shù)據(jù)庫

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 啟動PostgreSQL數(shù)據(jù)庫

# 開機自啟動
systemctl enable postgresql-13
# 啟動數(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遠程訪問

4.1 配置遠程訪問

# 修改/var/lib/pgsql/13/data/postgresql.conf配置文件,開啟遠程訪問。
# 刪除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 遠程連接PostgreSQL數(shù)據(jù)庫

終端連接

D:\Program Files\Postgresql\bin>psql -hxx.xx.xx.xx  -Upostgres -W
口令:
psql (11.2, 服務(wù)器 13.11)
輸入 "help" 來獲取幫助信息.

postgres=#

工具連接

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容