Brew postgresql-upgrade-database This formula has created a default database cluster with: initdb -locale=C -E UTF-8 $(brew -prefix)/var/postgres. [email protected]: 7,380: Installs on Request (30 days) [email protected]: 7,376: Build Errors (30 days) [email protected]: 1: Installs (90 days) [email protected]: 24,289: Installs on Request (90 days) [email protected]: 24,241: Installs (365 days) [email protected]: 97,556: Installs on Request (365 days) [email protected]: 97,020.
Install PostgreSQL via Homebrew
Likely most OS X users know of
Homebrew, but Homebrew is a package manager for OS X that allows you to easily install and run a massive library of applications and utilities with ease.
We won’t go through the entire (albeit short) installation process of Homebrew, but if you wish to install Homebrew and use it for PostgreSQL management, check out the installation command on the official documentation. If you aren’t sure if Homebrew is installed, try the
which brew command from the terminal to verify.
Postgresql Brew Manual
Once Homebrew is installed, you can install PostgreSQL by issuing the following commands in your terminal:
The first two commands are used to update Homebrew and report any potential issues (if necessary). Then, of course,
brew install postgres is the one-line command for installing PostgreSQL.
You should see a good deal of useful information in the output during installation, much of which should be copied down for use in the next sections.
Using a LaunchAgent and plist to Launch PostgreSQL on Startup
In most cases, you’ll likely wish to have PostgreSQL launch when you start up your system, so you’ll need to tell your computer this is your desire.
First, you’ll need to create a directory for your
LaunchAgents to reside (if the directory doesn’t exist already).
LaunchAgents in OS X are simple scripts used by
launchd that cause the system to run programs or code during startup.
Brew Install Psql
LaunchAgents directory with this command, if necessary:
Now you’ll need to create a symbolic link from the script that actually allows Postgres to run to the
LaunchAgents directory. A symbolic link is similar to creating a new copy of a file for use in another directory, but since the link is ‘symbolic’, the link is just a forwarding address: any request made to that symbolic link location is actually “forwarded along” or redirected to where the real file actually resides.
Link to the
plist (property list) file that was generated by Homebrew and place that new symbolic link in
LaunchAgents with this command:
Note: Double-check that the command is correct: It should’ve been part of the installation output mentioned above when Homebrew installed Postgres initially.
Finally, we load the new symbolic link’ed
LaunchAgent file using the
launchctl load command, which is specifically what informs the computer to run this script and start Postgres when the computer launches. Again, the exact command to enter for your own installation will be an output during Homebrew’s Postgres installation, but it should look something like this:
Manually Starting PostgreSQL
To manually startup Postgres without rebooting, again you should be able to use the command that was output during the installation, like so:
This will attempt to launch Postgres in
daemon mode, which means it will be running as a background process without taking over your terminal.
Start/Stop PostgreSQL Without Homebrew
Postgresql Brew Error
In the event that you don’t have (or don’t wish to use) Homebrew for Postgres, yet you have Postgres installed already, you can also manually start it with
pg_ctl, which is the launch utility provided by Postgres itself.
Postgresql Brew Start
This will start Postgres (assuming default directories):
And this will stop Postgres: Chatpsp unlimited.
Startup Troubleshooting: Did You Run
In some cases, if you have trouble running Postgres, be sure you’ve executed the
initdb command one time, which causes Postgres to initialize the database cluster for a new installation and allows you to connect with the default