Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Alias for Start/Stop Postgres as root

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use a function instead of an alias:

start_postgres() {sudo -u postgres pg_ctl -D /Library/PostgreSQL/14/data start}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading