Guest User

Untitled

a guest
Apr 7th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. ## Installing PostgreSQL
  2. * ensure that homebrew is installed: `brew install postgres`
  3. * fix errors if any (look below)
  4. * `initdb /usr/local/var/postgres` for **first** time!!!!!!
  5. * `pg_ctl -D /usr/local/var/postgres start` needs to be run in a terminal
  6. * add to `Gemfile`: `gem 'pg'`
  7. * `bundle install`
  8.  
  9. ## Setting up PSQL
  10. * Need to enter postgres, enter in terminal: `psql postgres`
  11. * Next, create a user (or role as postgres calls it):
  12. `create role myapp with createdb login password 'password';`
  13. * List all roles: `\du`
  14. * List all databases: `\l`
  15. * List all tables in the database: `\d`
  16. * Connect to another db: `\c dbname`
  17. * Describe (show) table: `\d dbname`
  18. * Quit: `\q`
  19.  
  20.  
  21. ## Connecting pgAdmin to Postgres DB
  22. * Open pgadmin
  23. * `File` > `Add Server` > `New Server Registration`
  24. * Set `Host` to `localhost` and `Port` to `5432` (default port unless set otherwise)
  25. * Double click on the server and enter password when prompted
  26.  
  27.  
  28. ## Creating Your Rails App for Postgres
  29. * `rails new myapp --database=postgresql`
  30. * Using rails 4.2.5, use `pg gem 'pg', '0.17.0'` in `Gemfile`
  31. * Keep the name of the app the same as the name of the psql user (can be changed)
  32.  
  33. ## Configuring the Rails App
  34. * In `config/database.yml`, consists of 3 different environments and thus 3 different db's!
  35. * Ensure that the `username` and `password` are the ones that were used when creating the user!!!
  36.  
  37. ```ruby
  38. development:
  39. adapter: postgresql
  40. encoding: unicode
  41. database: my_app_development
  42. pool: 5
  43. username: myapp
  44. password: password
  45.  
  46.  
  47. test:
  48. adapter: postgresql
  49. encoding: unicode
  50. database: my_app_test
  51. pool: 5
  52. username: myapp
  53. password: password
  54. ```
  55.  
  56. ## `bundle exec rake db:setup`
  57. * run the command above to _**create**_ the different database's!
  58.  
  59. ## Other tools
  60. * May want to install **pgAdmin** as a GUI to see your databases!
  61.  
  62. ## Errors Occuring with Installation
  63. * If you encounter:
  64.  
  65. ```
  66. Error: The `brew link` step did not complete successfully
  67. The formula built, but is not symlinked into /usr/local
  68. Could not symlink share/man/man3/SPI_connect.3
  69. /usr/local/share/man/man3 is not writable.
  70. ```
  71.  
  72. * Try this:
  73.  
  74. ```
  75. sudo chown -R `whoami` /usr/local/share/man/
  76. # enter password
  77. brew link postgresql
  78. # should say: Linking /usr/local/Cellar/postgresql/10.3... 377 symlinks created
  79. ```
Add Comment
Please, Sign In to add comment