1、 yum install -y https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-8.12-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2、yum -y install postgresql12
3、yum -y install postgresql12-server
4、/usr/pgsql-12/bin/postgresql-12-setup initdb
5、systemctl enable postgresql-12
6、systemctl start postgresql-12
7、su - postgres
#切換用戶后,提示符變更為“-bash-4.2$”;
#同時(shí)數(shù)據(jù)庫(kù)中也會(huì)生成一個(gè)名為”postgres”的數(shù)據(jù)庫(kù)用戶,且密碼已自動(dòng)生成;
#PostgreSQL在數(shù)據(jù)庫(kù)用戶同名的系統(tǒng)賬號(hào)下登錄免密;
psql -U postgres
#進(jìn)入數(shù)據(jù)庫(kù)后修改密碼;
postgres=# alter user postgres with password 'postgre';
\q 退出
exit 退出
這是外部是不能訪問的
8、找到pg_hba.conf? 一般在/var/lib/pgsql/12/data下
#在第82行之后,”IPv4 local connections”下新增允許的客戶端;
host all all 0.0.0.0/0 md5
9、?允許遠(yuǎn)程訪問
#默認(rèn)配置文件在/var/lib/pgsql/12/data/下postgresql.conf
#修改listen_addresses = 'localhost'為listen_addresses = '*',允許所有遠(yuǎn)程訪問;
10、設(shè)置環(huán)境變量
進(jìn)入配置文件 /etc/profile ,增加環(huán)境變量
export PATH=$PATH:/usr/pgsql-12/bin
11、重啟服務(wù)
systemctl restart postgresql-12