Solve the problem that postgresql cannot be started due to the modification of file permissions

Environment: macOS

Make a note of how my problem arose.
First of all, I need to change pg_hba.conf, so I need to enter the postgresql installation directory, but found that I do not have permission to enter "/Library/PostgreSQL/14/data", so I performed
chmod -R 777 data/, and successfully modified pg_hba.conf
but! When I tried to restart pgsql, I found an error!

Baidu searched for a round, but didn't solve it. Later, I found out that the original pgsql installation file defaults to all users as "postgres".
So I did chwon -R postgres data/.
But execute the start command, "/Library/PostgreSQL/14/bin/pg_ctl start -D /Library/PostgreSQL/14/DATA", still can not start, error "pg_ctl: could not open PID file "/Library/PostgreSQL/14/ DATA/postmaster.pid”: Permission denied”
Finally I switched the end user and it finally started successfully!
Execute commands in sequence

sudo su
输入密码

su - postgres
切换用户为postgres

启动pgsql
/Library/PostgreSQL/14/bin/pg_ctl start -D /Library/PostgreSQL/14/DATA

So far, the problem of "postgresql cannot be started due to the modification of file permissions" has been successfully solved"

In addition, record the commands and steps used to restart pgsql correctly

不修改任何文件权限!
不修改任何文件权限!
不修改任何文件权限!
1. sudo su
输入密码

2. su - postgres 
切换用户为postgres

3. 先进入到pgsql安装目录,假设为{pgsql_home}

4. 进入{pgsql_home}/bin

5. 执行停止服务命令,./pg_ctl stop -D {pgsql_home}/data 

6. 执行启动服务命令,./pg_ctl start -D /Library/PostgreSQL/14/DATA

Guess you like

Origin blog.csdn.net/u010775335/article/details/129125895