No connection to db issue

Hi All,

I am trying to set up Discourse on Windows subsystem for Linux and keep running into this issue. I must have gone through the steps at least 3 times now.

I got to the part of starting redis and postgres and successfully got them running.

And then I try to run the bundle exec rake db:create db:migrate command and then I run into this error.

I am positive I set my psql user to the same as my Ubuntu user. Went and changed the default passwords to my own and also tried it with the default passwords and still no dice. Been pulling my hair trying to fix this issue.

I have read that you may need to change the config file but I am unsure of how to do that through the Ubuntu terminal.

Thanks ahead of time.

Is this a Dev install, or are you looking to host a live instance on it?

this is for the dev install

And you’re following this guide?

2 Likes

Yup. Followed all the steps. Made sure my Ubuntu was downloaded properly and updated. Cloned the repo, created postgres role and installed the bundle in my project folder.

Looks like postgresql isn’t running.

Have you tried: sudo service postgresql start?

Yes. I’ve tried it many times now and then running the bundle exec.

Can you connect to the db manually via psql?

This is the error I get when I enter psql.
psqlnotconnect

What does sudo service postgresql status returns?

10/main (port 5433): down

I notice in this screenshot you are trying to connect to the socket corresponding to port 5432 whereas in this one:

It’s port 5433. Which seems to be the cluster you have set up:

Once it is actually running (sudo service postgresql start) you’ll need to ensure you connect to the right port.

1 Like

Once it is actually running ( sudo service postgresql start ) you’ll need to ensure you connect to the right port.

So I ran sudo service postgrresql start and it says Starting PostgreSQL database server and doesn’t say anything else.

I notice in this screenshot you are trying to connect to the socket corresponding to port 5432 whereas in this one
psqlnotconnect
It’s port 5433. Which seems to be the cluster you have set up:

I tried going into pg_hba.conf file and tried to set it to 5432 but it crashes my psql entirely. Is there a workaround I can do to make it 5432?

Ok. Seem to be getting somewhere. I restarted Ubuntu and ran the commands to start but now when I start the server it throws me this error psql: FATAL: database "jamesdev" does not exist

but when I try sudo -u postgres createuser -s jamesdev
I get this error createuser: creation of new role failed: ERROR: role "jamesdev" already exists

Right - so you need createdb not createuser

sudo -u postgres createdb jamesdev -O jamesdev

Right - so you need createdb not createuser
sudo -u postgres createdb jamesdev -O jamesdev

Just tried. Here’s my error: createdb: database creation failed: ERROR: database "jamesdev" already exists

dbs

So I took a look at my dbs and this is what showed up. Looks like the access privileges are missing?

Also tried dropping db and creating it a couple times and same error persists.

Edit: Deleted the database and created it again and modified with access privileges and I can see that it is now granted access privileges but still no dice.

Edit: also cannot post anymore for my first day :frowning:

LAST EDIT: I finally found the issue. I had postgresql installed in my Windows OS and it was set to default at port 5432 and Linux was not letting me change the port. After making sure my permissions and server were up and running I was finally able to run bundle exec and get everything spun up.