1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| 1. yum update -y 2. sudo yum install epel-release -y 3. zlib 在PSQL中pg_dump和pg_restort中压缩文档需要用到该包 yum install -y zlib.x86_64 zlib-devel.x86_64 4. Install the repository RPM: sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm 5. sudo yum install -y postgresql15-server
6.初始化数据库 /usr/pgsql-15/bin/postgresql-15-setup initdb
7.设置数据库开机自动启动后启动数据库 systemctl enable postgresql-15 systemctl start postgresql-15
8.检查postgresql数据库的操作系统用户 cat /etc/passwd
9.切换至postgres用户 su - postgres
10.启动PGSQL psql
11退出到操作系统下,看下后台进程 top -b -u postgres -d 1 -n 1 -c 展示内容: top - 16:35:46 up 25 min, 1 user, load average: 0.30, 0.34, 0.28 Tasks: 146 total, 1 running, 145 sleeping, 0 stopped, 0 zombie %Cpu(s): 1.2 us, 6.0 sy, 0.0 ni, 91.6 id, 1.2 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 7906204 total, 5118488 free, 1029596 used, 1758120 buff/cache KiB Swap: 8257532 total, 8257532 free, 0 used. 6600712 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2977 postgres 20 0 402048 17576 16124 S 0.0 0.2 0:00.06 /usr/pgsql-15/bin/postmaster -D /var/lib/pgsql/15/data/ 2979 postgres 20 0 253252 2108 688 S 0.0 0.0 0:00.00 postgres: logger 2980 postgres 20 0 402200 2316 800 S 0.0 0.0 0:00.00 postgres: checkpointer 2981 postgres 20 0 402184 3360 1856 S 0.0 0.0 0:00.02 postgres: background writer 2983 postgres 20 0 402184 6268 4768 S 0.0 0.1 0:00.01 postgres: walwriter 2984 postgres 20 0 403668 3344 1576 S 0.0 0.0 0:00.00 postgres: autovacuum launcher 2985 postgres 20 0 403652 3084 1352 S 0.0 0.0 0:00.00 postgres: logical replication launcher
12.需更改pg_hba.conf文件,在 vi /var/lib/pgsql/15/data/pg_hba.conf
修改内容如下:
host all all 127.0.0.1/32 scram-sha-256 host all all 0/0 md5
13.修改postgresq.conf文件,将listen_addresses改为* vi /var/lib/pgsql/15/data/postgresql.conf
修改内容如下: listen_addresses = '*'
14.修改登录PostgreSQL密码 su - postgres psql ALTER USER postgres WITH PASSWORD 'xxxxxxxxxxx'; 返回: ALTER ROLE 注: 密码postgres要用引号引起来,命令最后有分号
15.开放端口 firewall-cmd --zone=public --add-port=5432/tcp --permanent firewall-cmd --reload
16.重启数据库: systemctl restart postgresql-15
|