Check to see if you mac already has an older version of PostgreSQL installed:
If you see anything, that means you already have an older version of postgres installed.
Install PostgreSQL via Home Brew:
brew install postgresql
Somewhere in the output after PostgreSQL is installed you’ll see the version of your PostgreSQL you just installed.
Note the version of PostgreSQL you’ve installed. You’ll use it below.
Create Database Cluster
Create LaunchAgents directory if it doesn’t exist already
mkdir -p ~/Library/LaunchAgents
Setup file that allows you to Stop/Start the Postgres Server
cp /usr/local/Cellar/postgresql/[your postgres version]/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
Do the following if you already have a version of PostgreSQL installed so that instead the latest version of PostgreSQL will be used instead. (we will install the latest version below)
Edit your ~/.bash_login and add/modify so that /usr/local/bin/ loads first since that’s the location the new version of PostgreSQL will be copied to after you install it below.
open a new terminal or source your ~/.bash_login to pick up the new PATH.
Start up PostgreSQL server when your system boots
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Create Database User
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
Create Development and Test Databases
createdb -Oyour_db_user_name -Eutf8 your_project_development
createdb -Oyour_db_user_name -Eutf8 your_project_test
Set Postgres database passwords for Development Database
$ psql -U your_db_user_name your_project_development
Type “help” for help.
your_project_development=> ALTER USER your_db_user_name WITH PASSWORD ‘whateverpasswordyouwant’;
Set Postgres database passwords for Test Database
$ psql -U your_db_user_name your_project_test
Type “help” for help.
your_project_test=> ALTER USER your_db_user_name WITH PASSWORD ‘whateverpasswordyouwant’;
To Connect to Database (similar to mysql command)
psql -U your_db_user_name your_project_development
(to exit psql, type: \q)
Reinstall Gem pg so it can use the latest postgreSQL
gem uninstall pg
bundle or gem install pg
config/database.yml for Development database:
development: adapter: postgresql encoding: unicode database: your_project_development pool: 5 username: your_db_user_name password: whateverpasswordyouwantfromabove
config/database.yml for Test database:
development: adapter: postgresql encoding: unicode database: your_project_test pool: 5 username: your_db_user_name password: whateverpasswordyouwantfromabove
Leave a Reply