# Relation "selected" does not exist with external Postgres

**URL:** https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761
**Category:** Self-hosting
**Created:** [July 23, 2019, 6:01pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761 "2019-07-23T18:01:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jhuddle1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jhuddle1/32/183712_2.png) [@jhuddle1](https://meta.discourse.org/u/jhuddle1)
#### Post date: [July 23, 2019, 6:01pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/1 "2019-07-23T18:01:08Z")

</div>

Hello,  
I’m trying to set up a discourse server hosted off of a pair of servers that will act as a failover pair–to do so I need them to talk to the same database. I already have a postgres server running elsewhere so I followed the instructions [here](https://meta.discourse.org/t/running-discourse-with-a-separate-postgresql-server/46375) and it appears to connect okay. When I try to rebuild the app, however, I’ve been getting the error:

I, [2019-07-23T17:33:20.623719 #14] INFO – : \> cd /var/www/discourse && su discourse -c ‘bundle exec rake  
db:migrate’  
rake aborted!  
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedTable: ERROR: relation “selected” does not exist  
LINE 7: OR (t.closed AND tsp.execute\_at \>= now())  
^  
: WITH selected AS (  
SELECT tsp.id  
FROM topic\_status\_updates tsp  
JOIN topics t  
ON t.id = tsp.topic\_id  
WHERE tsp.execute\_at \< now()  
OR (t.closed AND tsp.execute\_at \>= now())  
)

UPDATE topic\_status\_updates  
SET deleted\_at = now(), deleted\_by\_id = -1  
WHERE id in (SELECT \* FROM selected)

When I go to the discourse database, there is no ‘selected’ table present. What can I do to fix this? I had an instance working when I had it locally off of once server–this only started happening once I moved the database.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [July 23, 2019, 10:12pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/2 "2019-07-23T22:12:48Z")

</div>

Does the database exist at all?

---

<div class="post-metadata">

### Author: ![jhuddle1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jhuddle1/32/183712_2.png) [@jhuddle1](https://meta.discourse.org/u/jhuddle1)
#### Post date: [July 23, 2019, 10:51pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/3 "2019-07-23T22:51:13Z")

</div>

It is—there are 125 tables in total when I access the database

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 23, 2019, 11:14pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/4 "2019-07-23T23:14:39Z")

</div>

> [@jhuddle1](#):
>
> When I go to the discourse database, there is no ‘selected’ table present.

That is expected, `selected` in this case is a [CTE](https://www.postgresql.org/docs/10/queries-with.html).

> [@jhuddle1](#):
>
> I already have a postgres server running elsewhere

What is the PostgreSQL version “elsewhere” ?

---

<div class="post-metadata">

### Author: ![jhuddle1](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jhuddle1/32/183712_2.png) [@jhuddle1](https://meta.discourse.org/u/jhuddle1)
#### Post date: [July 24, 2019, 12:15pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/5 "2019-07-24T12:15:55Z")

</div>

The version running on our database server is 9.4.22

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 24, 2019, 1:45pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/6 "2019-07-24T13:45:37Z")

</div>

Oh that is too old. Minimum supported version currently is PostgreSQL 10.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 23, 2019, 1:46pm UTC](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761/7 "2019-08-23T13:46:09Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
