# No connection to db issue

**URL:** https://meta.discourse.org/t/no-connection-to-db-issue/107210
**Category:** Self-hosting
**Created:** [January 22, 2019, 9:59pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210 "2019-01-22T21:59:11Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 22, 2019, 9:59pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/1 "2019-01-22T21:59:11Z")

</div>

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.

 ![unabletoconnect](https://global.discourse-cdn.com/meta/original/3X/0/0/000541f37827f82ec6f3be00bdc4d68325a1a252.jpeg)

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.

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [January 23, 2019, 4:43am UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/2 "2019-01-23T04:43:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:28am UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/3 "2019-01-23T05:28:00Z")

</div>

this is for the dev install

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [January 23, 2019, 5:29am UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/4 "2019-01-23T05:29:32Z")

</div>

And you’re following [this guide](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-windows-10-for-development/75149)?

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:31am UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/5 "2019-01-23T05:31:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 23, 2019, 4:12pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/6 "2019-01-23T16:12:29Z")

</div>

Looks like postgresql isn’t running.

Have you tried: `sudo service postgresql start`?

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 4:55pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/7 "2019-01-23T16:55:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 23, 2019, 4:56pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/8 "2019-01-23T16:56:30Z")

</div>

Can you connect to the db manually via `psql`?

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:03pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/9 "2019-01-23T17:03:45Z")

</div>

This is the error I get when I enter psql.  
 ![psqlnotconnect](https://global.discourse-cdn.com/meta/original/3X/1/0/10a152248f1ddaf1361de6628c6a28cc528e9ce1.jpeg)

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 23, 2019, 5:04pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/10 "2019-01-23T17:04:45Z")

</div>

What does `sudo service postgresql status` returns?

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:05pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/11 "2019-01-23T17:05:59Z")

</div>

`10/main (port 5433): down`

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [January 23, 2019, 5:08pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/12 "2019-01-23T17:08:08Z")

</div>

> [@James\_Park](#):
>
> ![unabletoconnect](https://global.discourse-cdn.com/meta/original/3X/0/0/000541f37827f82ec6f3be00bdc4d68325a1a252.jpeg)

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

> [@James\_Park](#):
>
> ![psqlnotconnect](https://global.discourse-cdn.com/meta/original/3X/1/0/10a152248f1ddaf1361de6628c6a28cc528e9ce1.jpeg)

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

> [@James\_Park](#):
>
> `10/main (port 5433): down`

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

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:14pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/14 "2019-01-23T17:14:30Z")

</div>

> 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](https://global.discourse-cdn.com/meta/original/3X/1/0/10a152248f1ddaf1361de6628c6a28cc528e9ce1.jpeg)  
> 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?

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:18pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/15 "2019-01-23T17:18:16Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [January 23, 2019, 5:24pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/16 "2019-01-23T17:24:34Z")

</div>

> [@James\_Park](#):
>
> database “jamesdev” does not exist

Right - so you need `createdb` not `createuser`

`sudo -u postgres createdb jamesdev -O jamesdev`

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:28pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/17 "2019-01-23T17:28:17Z")

</div>

> 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`

---

<div class="post-metadata">

### Author: ![James\_Park](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/james_park/32/129693_2.png) [@James\_Park](https://meta.discourse.org/u/James_Park)
#### Post date: [January 23, 2019, 5:34pm UTC](https://meta.discourse.org/t/no-connection-to-db-issue/107210/18 "2019-01-23T17:34:28Z")

</div>

![dbs](https://global.discourse-cdn.com/meta/original/3X/c/9/c9f5e80b61e3851cacb17d867ab2f48cbfce5e2d.jpeg)

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 ☹

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.
