I have a project in heroku. I have the URI that enables me to connect with the database in my external rails app. How do I change or set the search path in ruby code?

2 Answers 2


You can define it in your database.yml using the schema_search_path key with a string value

  adapter: postgresql
  schema_search_path: 'schema1,public'

You can find out a bit more here: https://til.hashrocket.com/posts/5aa2892b43-set-schema-search-path


For the session, when inside/connected with psql, you can use SETsearch_path =. Or you can use the GUC and change the default for the user or database which will impact all connections from the user or to the specified database.

  • ALTER ROLE myUsername SET search_path = ...
  • ALTER DATABASE myDatabase SET search_path = ...
  • can I set the path on my database.yml Nov 28, 2017 at 18:11
  • No, but you can connect with a user/(ROLE) with the right search path, or alter the search_path for the database. Nov 28, 2017 at 18:45
  • 1
    I am using ruby on rails.how do I do that? I have tried setting the search path but it has no effect, I keep on getting the public schema by default Nov 28, 2017 at 19:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.