Outdated note: the process is a lot easier now: after you brew install postgresql
you can initialize or stop the daemon with these commands: brew services start postgresql
or brew services stop postgresql
.
new out put may look like
To have launchd start postgresql now and restart at login:
brew services start postgresql
Or, if you don't want/need a background service you can just run:
pg_ctl -D /usr/local/var/postgres start
thank you commenters (sorry I didnt notice you all before but thankful for not getting notifications 🤭)
In your command-line run the following commands:
brew doctor
brew update
-
In your command-line run the command:
brew install postgresql
-
Read the Caveats section that is outputted to the Terminal. (out dated?)
-
Run the command:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
-
Open your zsh config file:
subl ~/.zshrc
-
At the bottom of the file, create two new aliases to start and stop your postgres server. They could look something like this:
alias pg-start="launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist" alias pg-stop="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"
-
Run the command:
source ~/.zshrc
to reload your configuration. -
Run the alias you just created:
pg-start
. Use this comment to start your database service.- alternatively,
pg-stop
stops your database service.
- alternatively,
-
Run the command:
createdb `whoami`
-
Connect to your postgres with the command:
psql
from the man ln
command
The ln utility creates a new directory entry (linked file) which has the same modes as the original file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the
copies''; instead, a link
points'' to the original copy. There are two types of links; hard links and symbolic links. How a link ``points'' to a file is one of the differences between a hard and symbolic link.
from the man launchctl
command
launchctl interfaces with launchd to manage and inspect daemons, angents and XPC services.
If you're using bash, your equivalent of the zsh file would be ~/.bash_profile you can add aliases there and they will be there for you interactive shells in OSX terminal
After editing that file, type
source ~/.bash_profile
to init the aliases, but it'll be there for any new terminals you open.