Forrest logo
back to the psql tool

psql:tldr:afdb1

psql: Connect to the database on given server host running on given port with given username, without a password prompt.
$ psql -h ${host} -p ${port} -U ${username} ${database}
try on your machine

This command is used to connect to a PostgreSQL database using the psql command-line utility. Here's the breakdown of the command and its arguments:

  • psql: The command itself, which is used to start the psql utility.
  • -h ${host}: Specifies the host (server) where the PostgreSQL database is running. ${host} is a placeholder for the actual host name or IP address. For example, -h localhost or -h 192.168.1.100.
  • -p ${port}: Specifies the port number on which the PostgreSQL database is listening for connections. ${port} is a placeholder for the actual port number. For example, -p 5432.
  • -U ${username}: Specifies the username to connect to the database. ${username} is a placeholder for the actual username.
  • ${database}: Specifies the name of the database you want to connect to. ${database} is a placeholder for the actual database name.

To use this command, you need to replace the placeholders ${host}, ${port}, ${username}, and ${database} with the appropriate values for your database connection. For example, the following command will connect to a database named "mydatabase" on the localhost using the default port (5432) and the username "myuser":

psql -h localhost -p 5432 -U myuser mydatabase
This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the psql tool