Forrest logo
back to the psql tool

psql:tldr:83e3a

psql: Connect to the database; user will be prompted for password.
$ psql -h ${host} -p ${port} -U ${username} -W ${database}
try on your machine

This command is used to connect to a PostgreSQL database using the psql command-line tool. Here's what each parameter represents:

  • psql: This is the actual command-line tool to interact with PostgreSQL.
  • -h ${host}: This specifies the hostname or IP address of the machine where the PostgreSQL server is running. The ${host} placeholder should be replaced with the actual host value.
  • -p ${port}: This specifies the port number on which the PostgreSQL server is accessible. The ${port} placeholder should be replaced with the actual port value.
  • -U ${username}: This specifies the username to use for authentication when connecting to the PostgreSQL server. The ${username} placeholder should be replaced with the actual username.
  • -W: This prompts for the password of the specified username. It ensures that the connection is password-protected. If you don't want to be prompted for the password, you can omit this parameter.
  • ${database}: This specifies the name of the database to connect to. The ${database} placeholder should be replaced with the actual database name.

Overall, this command initiates a connection to a PostgreSQL database server with the provided host, port, username, password, and database name.

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