# 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:** 1\
**Showing post:** 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.

---

_[View the full topic](https://meta.discourse.org/t/relation-selected-does-not-exist-with-external-postgres/123761)._
