Wednesday, July 15, 2015

aliasing psql

When you run psql without arguments, then the psql tries to connect to database named like current user. I dislike this behave. Surely I have not database "pavel". There is trivial solution - add to your .bashrc code:
function psql { 
if [[ $# -eq 0 ]]; then
   env psql postgres
else
  env psql "$@"
fi
}

3 Comments:

At July 15, 2015 at 10:35 PM , Anonymous Anonymous said...

Alternatively use the ENV:

export PGDATABASE=postgres

in .bashrc/.zshrc or similar

 
At July 15, 2015 at 10:48 PM , Blogger Pavel Stěhule said...

@anonymous: good to know, thank you

 
At July 16, 2015 at 6:15 AM , Blogger David Fetter said...

Similarly, you can set things like PGSERVICE in your environment if you're using psql to access remote systems most of the time. There are a fair number of other customizations of this type. http://www.postgresql.org/docs/9.5/static/app-psql.html#AEN9442

 

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home