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.
In PostgreSQL, an alias is a temporary alternative name for columns, tables, views, materialized views, etc. in a query. Aliases are assigned during query execution and aren't stored in the database or on disk. By using column aliases, the query output can become more meaningful.
The PostgreSQL Alias is used to assign a temporary name to a table or a column in a query. They only exist at the time of the query execution.
PostgreSQL uses a message-based protocol for communication between frontends and backends (clients and servers). The protocol is supported over TCP/IP and also over Unix-domain sockets.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With