1. 安裝服務器即可。
Yum install postgresql-server
Yum install postgresql-contrib
2. 驗證是否安裝成功:
rpm -aq| grep postgres
3. 安裝完成后,檢查postgresql的服務狀態
Systemctl status postgresql (一般不成功)
安裝postgresql后需要初始化數據庫
執行postgresql-setup initdb
4 .再次啟動postgresql服務
Systemctl status postgresql
5.啟用開機自啟動
systemctl enable postgresql-10 systemctl start postgresql-10
6.配置防火牆
firewall-cmd --permanent --add-port=5432/tcp firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload
7.修改用戶密碼
su - postgres 切換用戶,執行后提示符會變為 '-bash-4.2$'
psql -U postgres 登錄數據庫,執行后提示符變為 'postgres=#'
ALTER USER postgres WITH PASSWORD 'postgres' 設置postgres用戶密碼為postgres \q 退出數據庫
8.開啟遠程訪問
vim /var/lib/pgsql/10/data/postgresql.conf 修改#listen_addresses = 'localhost' 為 listen_addresses='*' 當然,此處‘*’也可以改為任何你想開放的服務器IP
9.信任遠程連接
vi m/var/lib/pgsql/10/data/pg_hba.conf 修改如下內容,信任指定服務器連接 # IPv4 local connections: host all all 127.0.0.1/32 trust host all all 192.168.157.1/32(需要連接的服務器IP) trust
10.重啟服務
systemctl restart postgresql-10
11.postsql數據庫命令psql -U postgres
出現以下界面,說明已經進入到想要的數據庫,可以進行想要的操作了。
template1=# 。比如:
\l --查看系統中現存的數據庫
create database test1DBName; --創建數據庫
\d --查看數據庫列表:
12 .安裝pgadmin4客戶端連接linux中安裝的postgresql。
