0
diesel migration list
Failed with: no schema has been selected to create in

This is the error I'm trying to solve. I recently made some changes to roles and permissions in Postgres, and now my diesel migrations won't run.

cat .env

The result shows that indexer1 is the pg user.

But I've looked at https://dba.stackexchange.com/a/106067/18098 and https://stackoverflow.com/questions/41207259/no-schema-has-been-selected-to-create-in-error and even opened up the permissions as much as I know how (temporarily sacrificing security).

postgres=# show search_path ;
   search_path   
-----------------
 "$user", public
(1 row)
 \dn+ public 
                          List of schemas
  Name  |  Owner   |  Access privileges   |      Description       
--------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres+| standard public schema
        |          | indexer1=UC/postgres+| 
        |          | =UC/postgres         | 
(1 row)

 \du
                                        List of roles
     Role name      |                         Attributes                         | Member of  
--------------------+------------------------------------------------------------+------------
 editor             | Cannot login                                               | {}
 indexer1           | Create DB                                                  | {}
 postgres           | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 readonly           | Cannot login                                               | {}

(I've omitted some additional roles that I think are irrelevant.)

UPDATE

I temporarily ran:

ALTER USER indexer1 WITH SUPERUSER;
\du

and now diesel migration list works.

But my question remains because this indexer1 user didn't need to be a superuser before.

What else should I check and adjust?

RESPONSE to first comment

What does the following result tell us?

\connect mainnet_node;
You are now connected to database "mainnet_node" as user "postgres".
mainnet_node=# show search_path ;
 search_path 
-------------
 public
(1 row)
mainnet_node=# \dn+ public 
                          List of schemas
  Name  |  Owner   |  Access privileges   |      Description       
--------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres+| standard public schema
        |          | editor=UC/postgres  +| 
        |          | readonly=U/postgres  | 
(1 row)

mainnet_node=# grant usage on schema public to indexer1;
GRANT
mainnet_node=# grant create on schema public to indexer1;
GRANT
mainnet_node=# \dn+ public 
                          List of schemas
  Name  |  Owner   |  Access privileges   |      Description       
--------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres+| standard public schema
        |          | editor=UC/postgres  +| 
        |          | readonly=U/postgres +| 
        |          | indexer1=UC/postgres | 
(1 row)

If I remove superuser from indexer1 now, will I probably be "back to normal"?

3
  • 2
    The error you show is not a permissions issue. It happens when search_path is empty, or is set only to schemas which don't exist. If the schema exists but you don't have permissions, that would give a different error message. Presumably the search_path you showed is for a connection other than the one experiencing the problem.
    – jjanes
    Oct 26, 2022 at 18:50
  • @jjanes Interesting. Thank you! I updated the question above. You may have figured it out.
    – Ryan
    Oct 26, 2022 at 18:59
  • @jjanes Yes, I think that solved it. If you write an answer, I'll mark as accepted! Thanks. After ALTER USER indexer1 nosuperuser;, diesel migration list still works! 🎉
    – Ryan
    Oct 26, 2022 at 19:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.