1

Newbie to Postgres, basic skills with Rails, so bear with me.

I will explain the process of how I got to where I am, in case I did anything wrong along the way.

What I did.

I created a Rails 5 project (using the actual Git repo) and, once it was created successfully, I found the default gem sqlite3 in the Gemfile.

Now, I want to work with Postgres, so I turned sqlite3 into pg, and ran bundle install. Worked perfectly, Rails didn't complain.

Then, I installed Postgres on my computer (using the latest OS X) and ran createdb testDB. It's an empty database.

Now, I have to configure the database.yml file. After going through a dozen of links and resources, I changed the file's contents to the following:

default: &default
  adapter: postgresql
  database: testDB
  username: postgres
  password: password
  host: localhost
  port: 9057


development:
  <<: *default

test:
  <<: *default

production:
  <<: *default
  database: someOtherDB

I am certain that the port number is correct, because I set it manually, and I can check that it's running using the command netstat -na. I get the following two lines:

tcp6       0      0  *.9057                 *.*                    LISTEN     
tcp4       0      0  *.9057                 *.*                    LISTEN    

Now, in order to change the password for postgres to ensure it's actually the cleverly secure string password, I ran the following commands:

$ sudo -u postgres psql template1

Opens up the psql prompt, then I run the command:

psql (9.3.4)
Type "help" for help.

template1=# ALTER USER postgres PASSWORD 'password';

Which returned:

ALTER ROLE

Yay! Password's changed! Now I can open up my first ever working Rails app with a Postgres backend!

What I got.

I run bin/rails server, and I get the following error:

The error I get

Some more info that may be helpful.

When I run the command psql -l, I get the following:

                                        List of databases
   Name    |    Owner     | Encoding |   Collate   |    Ctype    |       Access privileges       
-----------+--------------+----------+-------------+-------------+-------------------------------
 postgres  | myusername | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 template0 | myusername | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/myusername              +
           |              |          |             |             | myusername=CTc/myusername
 template1 | myusername | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | =c/myusername              +
           |              |          |             |             | myusername=CTc/myusername
 test      | myusername | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
 testDB    | myusername | UTF8     | en_GB.UTF-8 | en_GB.UTF-8 | 
(5 rows)

If I run psql X (where X is any of the databases listed above) followed by running the command \du, I get the following.

                               List of roles
  Role name   |                   Attributes                   | Member of 
--------------+------------------------------------------------+-----------
 myusername   | Superuser, Create role, Create DB, Replication | {}
 postgres     | Superuser                                      | {}

I followed instructions on this link and a few others to no avail.

What am I doing wrong?

Thank you so much in advance.

EDIT: Here's the content of log/development.log.

8
  • 1
    Is there anything in log/development.log? Commented Nov 9, 2015 at 23:34
  • 1
    On a side note - don't use the same database for tests and development. Your test suite should clean up the test database on every test run - while you might actually want to have some sample data in your development environment so that you can see what your app will look like with data. Commented Nov 9, 2015 at 23:40
  • 1
    Also this might sound pretty obvious but make sure you have restarted your rails server - database.yml is only read when the server starts - not per request. Commented Nov 9, 2015 at 23:43
  • 1
    One thing that might be worth a try is setting up a user with CREATE ROLE rails_dev WITH LOGIN CREATEDB PASSWORD NULL from psql and then change username: 'rails_dev' and comment out the password: in database.yml. Commented Nov 10, 2015 at 0:01
  • 1
    Let us continue this discussion in chat. Commented Nov 10, 2015 at 0:10

1 Answer 1

1

The default login for rails is the current username logged in and a blank password.

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

1 Comment

Thanks for this, @hd1! After our discussion on chat, I took off the username and password attributes and it worked.

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.