查看service----cd /usr/lib/systemd/systempostgresql-18.servicesudo yum install -y postgresql18-server postgresql18 --nogpgcheckInstalled:postgresql18-18.4-2PGDG.rhel8.10.x86_64postgresql18-libs-18.4-2PGDG.rhel8.10.x86_64postgresql18-server-18.4-2PGDG.rhel8.10.x86_64Complete!Index of /pub/repos/yum/18/redhat/rhel-8-x86_64/https://download.postgresql.org/pub/repos/yum/18/redhat/rhel-8-x86_64/下载这三个RPM即可五、初始化数据库sudo /usr/pgsql-18/bin/postgresql-18-setup initdbInitializing database ... OK手动创建sudo /usr/pgsql-18/bin/initdb -D /path/to/new_pgdata六、启动并设置开机自启sudo systemctl enable postgresql-18sudo systemctl start postgresql-18sudo systemctl status postgresql-18七、验证安装psql --version八、基础使用首次登录su - postgrespsql示例建库CREATE DATABASE testdb;\qexit一键获取完整项目代码九、开启远程访问可选 / 生产建议收紧1️⃣ 修改监听地址sudo vi /var/lib/pgsql/18/data/postgresql.conflisten_addresses *2️⃣ 修改认证规则sudo vi /var/lib/pgsql/18/data/pg_hba.conf追加host all all 0.0.0.0/0 md53️⃣ 重启sudo systemctl restart postgresql-18一键获取完整项目代码4️⃣ 防火墙 / 安全组sudo firewall-cmd --add-port5432/tcp --permanentsudo firewall-cmd --reload 同时在腾讯云控制台 → 安全组放行 TCP 5432----------------------如果要改变PGDATA/usr/pgsql-18/bin/initdb -D /path/to/new_pgdatacd /usr/lib/systemd/systempostgresql-18.service# Location of database directoryEnvironmentPGDATA/xxx/xxx/xx---如果用pg_ctl 启动的PG 不能用 systemctl stop postgresql-18.service 关闭也不能再次启动需要pg_ctl 关闭后用 systemctl start postgresql-18.service才能使用 systemctl status postgresql-18.service