This error mostly occurs when you forcefully stop the working of the PostgreSQL in any way.
If you have installed with Brew then now I will show you how to fix this issue as:
First of all, we need to check and stop the working of the PostgreSQL because if we do not stop this, then the database will be corrupted.so to prevent that we need to stop the Brew services using the Brew services stop PostgreSQL.
Now the first step is to remove the Postmaster.pid file, which will remove all the stoped processes.
Now, as usual, we need to start Brew services again, which will allow us to eliminate those errors and start the PostgreSQL working still.