3

I am trying to prompt the psql interface to try to create a database, actually following from Dr. Hartl's tutorials http://ruby.railstutorial.org/book/ruby-on-rails-tutorial?version=3.2.

I created the project with:

rails new postgr_ --database=postgresql

I added passwords to the database.yml file:

development:
  adapter: postgresql
  encoding: unicode
  database: postgr__development
  pool: 5
  username: postgr_
  password: 12345

test:
  adapter: postgresql
  encoding: unicode
  database: postgr__test
  pool: 5
  username: postgr_
  password: 12345

production:
  adapter: postgresql
  encoding: unicode
  database: postgr__production
  pool: 5
  username: postgr_
  password: 12345

I then enter into terminal:

$ rails db

And I get the following error after entering my password:

psql: FATAL:  password authentication failed for user "postgr_"

I've been going at this a good part of yesterday and all day today and was unable to work around this. I may very well be missing something fundamental, if you spot it please let me know. Thank you!

5
  • Do you have a postgr_ using inside PostgreSQL? Commented Oct 29, 2012 at 2:04
  • postgr_ is the project name and username. I do not know where or what file to look. Commented Oct 29, 2012 at 2:09
  • @mu is too short: does the pgadmin app for PostgreSQL need to be modded to run? any help is appreciated, thank you! Commented Oct 29, 2012 at 19:35
  • Sorry, no idea, I don't use pgadmin. Commented Oct 29, 2012 at 19:36
  • is there any method you would suggest i try? So far it seems i either can't enter the correct password or run into the psql: could not connect to server: Permission denied Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? error Commented Oct 29, 2012 at 19:40

1 Answer 1

2

You're missing the steps to setup the postgresql role and database creation.

This procedure depends on the system you are using. I will assume that you are using a mainstream linux distribution. First login to the postgresql account. You may use one of the following commands:

$ su - postgres

or

$ sudo -i -u postgres

Once logged in, start the psql program:

$ psql template1

At the psql prompt, create a new user role and a database for your project:

=> create role postgr_ with createdb login password '12345';

Then simply quit the program

=> \q

And logout from the postgresql user account

$ exit

Then you should be able to run the rail db command successfully

Sign up to request clarification or add additional context in comments.

13 Comments

Thank you. I go to: $ sudo postgres receive: "root" execution of the PostgreSQL server is not permitted. and for the su command, get: su: Sorry
Do you have local administrator priviledges on this machine?
absolutely, sorry for the delay. The error also states 'The server must be started under an unprivileged user ID to prevent possible system security compromise. See the documentation for more information on how to properly start the server.'
@aug2uag The sudo command was wrong; sudo postgres will try to run the command postgres (which is the PostgreSQL server back-end) as root. You want sudo -u postgres -i for an interactive login as user postgres, or you want sudo -u postgres psql template to just run psql directly as user postgres. I have corrected the answer.
the '=>' symbol indicate the prompt of the psql program, not something you must write to the shell prompt.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.