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.

Community
  • 1
  • 1
Fares K. A.
  • 1,273
  • 5
  • 24
  • 47
  • 1
    Is there anything in `log/development.log`? – hd1 Nov 09 '15 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. – max Nov 09 '15 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. – max Nov 09 '15 at 23:43
  • Hi @hd1, here's the content. Also added it to the post. http://pastebin.com/piCtuX43 – Fares K. A. Nov 09 '15 at 23:50
  • @max Thanks for the tip! I am restarting the server every time, still getting the same error. – Fares K. A. Nov 09 '15 at 23:50
  • 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`. – max Nov 10 '15 at 00:01
  • @max I'm not sure if it's Rails 5, but it won't take it without a password. See screenshot: http://i.imgur.com/1BOHeSJ.png – Fares K. A. Nov 10 '15 at 00:09
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/94658/discussion-between-max-and-fares-k-a). – max Nov 10 '15 at 00:10

1 Answers1

1

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

hd1
  • 33,938
  • 5
  • 80
  • 91
  • Thanks for this, @hd1! After our discussion on chat, I took off the username and password attributes and it worked. – Fares K. A. Nov 10 '15 at 00:36