0

I have multiple databases that I am logging into on AWS and right now I am entering the full url for the database i.e.,

psql -d psql -d postgresql://user:pass@host:port/dbname more stuff

I would like to do something link this.

Where I have some kind of config file like from the example I linked,

Name my_database1
    Hostname=host_to_database
    Port=port_to_database
    User=username
    Pass=password
    DBName=dbname
Name my_database2
    Hostname=host_to_database2
    Port=port_to_database2
    User=username2
    Pass=password2
    DBName=dbname2

Then I would just have to run psql -d my_database1 How do I do that?

  • 1
    Set some variables? psql -d $my_database1 – Patrick Mar 29 '18 at 4:15
0

It is unlikely you would be able to get to a point where you literally were able to type psql -d my_database1, however you could use shell variables (as suggested in @Patrick's comment) or aliases to accomplish remembering/typing less.

I tend to use linux aliases, but straight from that alias page (emphasis my own):

The alias command is built into a number of shells including ash, bash (the default shell on most Linux systems), csh and ksh. It is one of several ways to customize the shell (another is setting environmental variables).

For example, you could create a ~/.profile (or append to it) with something along these lines:

alias psql_my_database1="psql -d postgresql://user:pass@host:port/dbname more stuff"
alias psql_my_database2="psql -d postgresql://user:pass@host:port/otherdbname"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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