(PostgreSQL) How to connect a DB with a connection URI with psql

I presume that you use psql as below when you connect to a DB.

psql -h {host name} -p {port} -U {user name} -d {database name}

This style cannot contain a DB password as an option. So you need to use PGPASSWORD or .pgpass file If you want to connect a DB in a shell script.

You can use a connection URI to connect a DB as below.

psql "postgresql://{host name}:{port}/{database name}?user={user name}&password={password}"

Connection URIs can contain a DB password as a parameter. This is useful to connect DB in a shell script.

PostgreSQL

Posted by fanfanta