Debugging “relation does not exist” error in postgres

Rajya Vardhan Mishra
2 min readMay 1, 2018

--

So, i was getting this nasty error even when the table clearly existed in t11 database.

Database Name:       t11
Schema: public
Table Name: userinfo5
Connection String: "host=localhost port=5432 user=postgres password= dbname=t11 sslmode=disable"

Even after lot of googling, debugging and trying Stackoverflow solutions, there was no resolution. Then i got a hunch, that i should check what database and schema were actually being used when done programmatically (even though dbname was clearly provided in connection string).

If you use database t11 by running \c t11 and then run:

select * from information_schema.tables where table_schema NOT IN (‘pg_catalog’, ‘information_schema’)

It will tell you that userinfo5 does exist in t11 database. But what happens when we try to access it programmatically?

So, i ran above query in a golang function, the function which was earlier running query select * from userinfo5 where id=1

Output showed that database name which was actually being used was postgres and not t11 Why?

Because, my postgres user was configured to not use password. But my connection string had password= This was somehow confusing the DB driver and postgres database was being used and not t11.

Solution 1:

remove password= from connection string so that it looks like: “host=localhost port=5432 user=postgres dbname=t11 sslmode=disable”

Solution 2:

  1. Alter user postgres so that it uses password: alter user postgres with password ‘pwd123’;
  2. Change connection string: “host=localhost port=5432 user=postgres password=pwd123 dbname=t11 sslmode=disable”

--

--

Rajya Vardhan Mishra
Rajya Vardhan Mishra

Written by Rajya Vardhan Mishra

Passionate Engineering Leader @Google. On a mission to make this world a better place. Driven by Optimism, Gratitude, Curiosity, & Determination.

Responses (8)