参考:https://blog.csdn.net/justlpf/article/details/84769813
说明: 安装及执行postgresql必须不能使用root用户,可创建个新用户postgres来安装。本示例规划的数据存放目录为/mnt/data1/data/appdata/postgresqldata,postgresqldata的目录权限必须为0750,不能是777,不然无法启动。
groupadd postgres && useradd postgres && usermod -a -G postgres postgres
su postgres
yum install postgresql11 -y
yum install postgresql11-server -y
cd /mnt/data1/data/appdata/
chmod -R 0750 postgresqldata
chown -R postgres:postgres postgresqldata/
/usr/pgsql-11/bin/initdb -D /mnt/data1/data/appdata/postgresqldata
添加环境变量 vim /etc/profile 在最后添加 export PGDATA=/mnt/data1/data/appdata/postgresqldata 然后生效: source /etc/profile
修改postgresql的配置vim /usr/lib/systemd/system/postgresql-11.service,将“Environment=PGDATA=/var/lib/pgsql/11/data/”注释掉,替换为“Environment=PGDATA=/mnt/data1/data/appdata/postgresqldata”,保存。
下面的相关的命令
root用户执行: systemctl enable postgresql-11
/usr/pgsql-11/bin/pg_ctl -D /mnt/data1/data/appdata/postgresqldata -l /mnt/data1/data/appdata/postgresqldata/logs/pgsql.log start
service postgresql-11 initdb -D /mnt/data1/data/appdata/postgresqldata
systemctl status postgresql-11
重启: /usr/pgsql-11/bin/pg_ctl restart 不能执行 systemctl restart postgresql-11
执行命令。先执行psql
创建用户: create user adminuser with password 'postgrespassword';
修改密码: ALTER USER postgres WITH PASSWORD 'postgrespassword';