1.下載rpm文件
2.官網選擇后如下
3.命令執行
安裝rpm文件
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
搜索postgresql10的包
yum search postgresql10
安裝server和contrib
yum install -y postgresql10-server postgresql10-server
需要先執行初始化命令
/usr/pgsql-10/bin/postgresql-10-setup initdb
啟動postgresql或者關閉postgresql
systemctl enable postgresql-10 systemctl start postgresql-10 service postgresql-10 start service postgresql-10 stop
密碼設置
1、Postgr eSQL登錄(使用psql客戶端登錄)
# sudo -u postgres psql
//其中,sudo -u postgres 是使用postgres 用戶登錄的意思
//PostgreSQL數據默認會創建一個postgres的數據庫用戶作為數據庫的管理員,密碼是隨機的,所以這里
//設定為'postgres'
2.修改PostgreSQL登錄密碼:
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
//postgres=#為PostgreSQL下的命令提示符
3.退出PostgreSQL psql客戶端
postgres=# \q
修改linux系統的postgres用戶的密碼(密碼與數據庫用戶postgres的密碼相同),這種修改好像密碼有特殊要求,不能包含postgres,不能設置太簡單
1.刪除PostgreSQL用戶密碼
# sudo passwd -d postgres
passwd: password expiry information changed.
//passwd -d 是清空指定用戶密碼的意思
2.設置PostgreSQL用戶密碼
PostgreSQL數據默認會創建一個linux用戶postgres,通過上面的代碼修改密碼為'postgres’(這取決於
第二步中的密碼,只要與其相同即可)。
#sudo -u postgres passwd
輸入新的 UNIX 密碼:
重新輸入新的 UNIX 密碼:
passwd:已成功更新密碼
兩處修改:
1.postgresql.conf
listen_addresses項值設定為“*”,在9.0 Windows版中,該項配置已經是“*”無需修改。
listen_addresses='*'
2.pg_hba.conf
host all all 127.0.0.1/32 md5行下添加以下配置
host all all 0.0.0.0/0 md5
如果不希望允許所有IP遠程訪問,則可以將上述配置項中的0.0.0.0設定為特定的IP值。
Linux下可通過find . -name "pg_hba.conf" 查找文件位置
利用navicat客戶端連接postgresql
到此,postgresql安裝操作完成。