> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connecting to PostgreSQL using the command line

> Learn to quickly connect to a PostgreSQL database using the psql command line tool.

This article describes how to connect to a PostgreSQL database from the command line using the *psql* program. You can use the *psql* program as a quick and easy way to access your databases directly.

*psql* is an interactive terminal that allows you to run PostgreSQL queries and examine the results. *psql* also has a number of meta-commands and shell-like capabilities that make building scripts and automating a range of activities easier.

## Connecting to PostgreSQL using psql

To connect to PostgreSQL from the command line, follow these steps:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. At the command line, type the following command. Replace ***dbname*** with the name of the database, and ***username*** with the database username:

   ```bash theme={null}
   psql dbname username
   ```

3. At the **Password** prompt, type the database user's password. When you type the correct password, the psql prompt appears.

4. After you access a PostgreSQL database, you can run SQL queries and more. Here are some common *psql* commands:

   * To view help for *psql* commands, type `\?`.

   * To view help for SQL commands, type `\h`.

   * To view information about the current database connection, type `\conninfo`.

   * To list the database's tables and their respective owners, type `\dt`.

   * To list all of the tables, views, and sequences in the database, type `\z`.

   * To exit the *psql* program, type `\q`.

## More information

* To view the online documentation for psql in PostgreSQL 8.4, please visit [http://www.postgresql.org/docs/8.4/static/app-psql.html](http://www.postgresql.org/docs/8.4/static/app-psql.html).

* To view the online documentation for psql in PostgreSQL 9.1, please visit [http://www.postgresql.org/docs/9.1/static/app-psql.html](http://www.postgresql.org/docs/9.1/static/app-psql.html).

## Related articles

* [Creating a PostgreSQL installation for local testing](/docs/creating-a-postgresql-installation-for-local-testing)

* [Importing and exporting a PostgreSQL database](/docs/import-and-export-a-postgresql-database)

* [Managing PostgreSQL databases and users](/docs/managing-postgresql-databases)

* [Managing PostgreSQL databases and users from the command line](/docs/managing-postgresql-databases-and-users-from-the-command-line)
