Last active
January 21, 2016 13:28
-
-
Save 0xGGGGG/4486720 to your computer and use it in GitHub Desktop.
postgres install and develop applications on MAC OSX with rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first install pgsql with home brew | |
brew install postgresql | |
# at this point, you need to be sure you have /usr/local/bin before /usr/bin on your $PATH | |
# to see, run: | |
brew doctor | |
# if doctor does not complain about this issue you can pass this step. | |
# prepend /usr/local/bin to your PATH in your ~/.bash_profile | |
# | |
# PATH=/usr/local/bin:$PATH | |
# then reload your terminal, | |
## either restarting it | |
## or entering source command: | |
source ~/.bash_profile | |
# then fix some MAC OSX related variables to work with initdb | |
## if you do want that variables to be persistent, then add them to /etc/sysctl.conf | |
sudo sysctl -w kern.sysv.shmall=65536 | |
sudo sysctl -w kern.sysv.shmmax=16777216 | |
# after that initialize main db | |
initdb /usr/local/var/postgres -E utf8 | |
# then start psql | |
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start | |
## at any point you can stop pg by entering; | |
# pg_ctl -D /usr/local/var/postgres stop -s -m fast | |
# create your rails application by specifying database as psql | |
## this process will add boilerplate config/database.yml file | |
## with postgres role specific to your rails application. | |
### ... | |
### development: | |
### adapter: postgresql | |
### encoding: unicode | |
### database: app_name_development | |
### pool: 5 | |
### username: app_name | |
### password: | |
### ... | |
rails new app_name -d postgresql | |
# change directory to your application folder | |
cd app_name | |
# now add your app role to pgsql | |
## first login | |
psql -d postgres | |
## when you are inside of postgres=#, | |
## add your role with login and createdb permissions | |
# postgres=# create role app_name login createdb; | |
# it will be better if we reinstall all related pg gems | |
gem uninstall pg # uninstall all | |
bundle | |
## finally, run rake task to create initial database | |
rake db:create:all | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment