James Burke
James Burke

Reputation: 2387

PSQL connection alias

Is it possible to create a connection alias for psql?

For example, instead of having to type out:

psql --host=pr-gis-db --username=peregrinius --port=5432

I just type

psql pr-gis-db

And it connects with pre-configured settings.. Maybe prompts for password instead of storing it.

Upvotes: 18

Views: 5524

Answers (1)

James Burke
James Burke

Reputation: 2387

following the instructions here: https://www.postgresql.org/docs/current/static/libpq-pgservice.html

Create/update the file ~/.pg_service.conf

[pr-gis-db]
host=pr-gis-db
user=peregrinius
dbname=gis
port=5432

to run the alias connection

psql service=pr-gis-db

Note: you can also overwrite parameters in the file if you specify them when calling the service.

psql service=pr-gis-db -U dbadmin

Upvotes: 33

Related Questions