I am trying to use PostgreSQL so that I can deploy to Heroku. However I cannot run localhost anymore why? I get the following message:
PG::ConnectionBad
FATAL: role "Myname" does not exist
Here is my databse.yml
development:
adapter: postgresql
database: my_database_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: my_database_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: my_database_production
pool: 5
timeout: 5000
Here is my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'
# Use pg as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'rails_12factor', group: :production
It seems that pg needs me to create a user or databse however I am unable to or don't know how. Couldn't find any commands that worked for me(I'm on a windows btw)
What can I do?
The error is "role "Myname" does not exist",
create the user "Myname" for Postgresql
sudo -u postgres createuser --superuser Myname
it will solve this issue.
What worked for me was: createuser -P -d -e Myname
.
-P If given, createuser will issue a prompt for the password of the new user.
This is not necessary if you do not plan on using password authentication.
-d The new user will be allowed to create databases.
-e Echo the commands that createuser generates and sends to the server.
If you install Postgresql with homebrew on OSX, there is no default postgres
user, and you won't be able to use psql
directly without setting up a user first.
@user3408293
After the installation create a user for postgresql
sudo -u postgres createuser --superuser $USER
sudo -u postgres createuser pgs_root
Set user password for the postgresql user
sudo -u postgres psql postgres
( For psql prompt) postgres=# \passsword for ex.- postgres=# \passsword pgs_root
N.B You should also add username and password to different environments in database.yml file.
You can also refer this link: Rails: Error installing pg gem
You should create a username
and password
for your Postgresql
Try creating a user with password in psql
CREATE USER Myname WITH PASSWORD 'your_password';
And your should add those to your database.yml
as
username: Myname
password: your_password
On Windows, I believe it is a little easier.
Install postgresql and PGAdmin for your system. See this
Create a user named postgres and give it a password. You will be nicely prompted to do this.
Then, when you want to create databases, just right click on your connection and choose New Database. The names of these databases should correspond to what is written in your database.yml
Run rake db:migrate RAILS_ENV=development
(development| test| production).
These steps worked for me.
I had to go into my PG admin dashboard and create a db/user there. Unfrotunately it was in a subdirectory different from what the tutorials online said(probably updated directory destination last update). Fortunately I was able to find it and create the table/user there, update my database.yml file and then my app was able to work!