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
FATA
@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
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.
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.
Use this command to use your Postgres user:
sudo su - postgres
Now use this command to create a user:
createuser -s -r 'user_name'
Now logout.
The error is resolved.
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.
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!