1. 安裝依賴包
[centos@host ~]$ sudo dnf install gcc gcc-c++ epel-release clang libicu-devel perl-ExtUtils-Embed readline readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel openldap-devel systemd-devel tcl-devel bzip2
2. 下載軟件
[centos@host ~]$? wget https://ftp.postgresql.org/pub/source/v13.1/postgresql-13.1.tar.bz2
3. 解壓并安裝
[centos@host ~]$? tar -jxvf postgresql-13.1.tar.bz2
[centos@host ~]$? ./configure --prefix=/usr/local/pgsql
[centos@host ~]$? make
[centos@host ~]$? sudo make install
4. 添加用戶并更改權(quán)限
[centos@host ~]$? useradd postgres
[centos@host ~]$? passwd postgres
[centos@host ~]$? mkdir -p /data/pgsql/{data,log}
[centos@host ~]$? touch /data/pgsql/log/pgsql.log
[centos@host ~]$? chown -R postgres:postgres /data/pgsql
5. 添加環(huán)境變量
[centos@host ~]$? vi /etc/profile
export PGHOME=/usr/local/pgsql
export PGDATA=/data/pgsql/data
export PATH=$PGHOME/bin:$PATH
:wq
使之生效
[centos@host ~]$? source /etc/profile
6. 初始化數(shù)據(jù)
[centos@host ~]$? su postgres
[postgres@host ~]$? cd /usr/local/pgsql/bin/
[postgres@host ~]$? ./initdb -D /data/pgsql/data
7. 配置文件說明
pg_hba.conf? 是訪問控制配置文件鸠删;
postgresql.conf? 是postgresql的主配置文件抱完。
8. 修改pg_hba.conf文件
將該文件中的IPV4的連接修改為
# IPv4 local connections:
host all all 0.0.0.0/0 trust
##表示信任來自所有id連接的客戶端
9.修改postgresql.conf配置文件
將 localhost 改為 *,表示監(jiān)聽所有的網(wǎng)絡(luò)連接刃泡。其他的參數(shù)保持默認(rèn)即可巧娱。
listen_addresses = '*'
10. 啟動數(shù)據(jù)庫
[postgres@host ~]$? cd /usr/local/pgsql/bin/
[centos@host ~]$ ./pg_ctl -D /data/pgsql/data -l /data/pgsql/log/pgsql.log start
11.停止數(shù)據(jù)庫
[centos@host ~]$? pg_ctl -D /data/pgsql/data/ -l /data/pgsql/log/pgsql.log stop
12. 登錄數(shù)據(jù)庫并設(shè)置密碼
[postgres@host ~]$? cd /usr/local/pgsql/bin/
[centos@host ~]$? ./psql
postgres=# \password
Enter new password:
Enter it again:
postgres=# alter user postgres with password 'password';
postgres=# \q