I have installed Postgres on my M1 mac using a dmg file which I downloaded from their website. The homebrew installation was causing some issues, that’s why I installed it this way.
Previously with homebrew I could start/stop postgres using brew services start/stop postgres. Currently I have to do this
sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data start/stop to start/stop the server. I tried to make things a bit easier by adding an alias to .zshrc file, but as I learned I can’t just add a command to shell with sudo like that.
My question is there any way to add an alias to simplify the start/stop of postgres.
>Solution :
Use a function instead of an alias:
start_postgres() {sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data start}