skip to Main Content

I use psql to connect to multiple databases which contain multiple schemas. I usually use just one schema per db. Is it possible to set the default schema for a particular db via some psql config option or envariable?

2

Answers


  1. You can use the env variable PGDATABASE to specify the default database.

    export PGDATABASE=my_default_db
    

    Maybe you can place it in your .bashrc

    Login or Signup to reply.
  2. You can set the parameter search_path for each database:

    ALTER DATABASE mydb1 SET search_path = myschema1, public;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search