For Unix environnement the command line is

psql -U USERNAME -h localhost dbname

For a Windows environment, you may consider replacing "-" with "/"

-U option able you to choose a user to connect with

-h option able you to connect with the TCPIP protocol, you may consider it useless for Windows

Answer from Charkan on Stack Overflow
🌐
PhoenixNAP
phoenixnap.com › home › kb › databases › how to connect to a postgresql database from linux or windows
How to Connect to a PostgreSQL Database from Linux or Windows
December 12, 2025 - PostgreSQL can support and maintain ... to list available users and databases: ... Use the \c command and the database name to connect to a different database owned by the postgres user:...
🌐
EnterpriseDB
enterprisedb.com › postgres-tutorials › connecting-postgresql-using-psql-and-pgadmin
Connecting PostgreSQL using psql and pgAdmin | EDB
However, if it errors out, you can locate the psql utility by searching for the file with the following command on terminal: [root@localhost /]# find / -name psql /usr/edb/as11/bin/psql · On Windows, you can find psql in the Program Files, and you should be able to launch it in a command prompt simply by clicking on it. On a Mac you should be able to locate psql under the Applications > PostgreSQL (version number) > SQL Shell (psql). Now that we have located psql, we need to understand what it requires to connect to the database.
🌐
PostgreSQL
postgresql.org › docs › current › tutorial-accessdb.html
PostgreSQL: Documentation: 18: 1.4. Accessing a Database
May 14, 2026 - The last line printed out by psql is the prompt, and it indicates that psql is listening to you and that you can type SQL queries into a work space maintained by psql. Try out these commands: mydb=> SELECT version(); version -------------------------------------------------------------------​----------------------- PostgreSQL 18.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit (1 row) mydb=> SELECT current_date; date ------------ 2016-01-07 (1 row) mydb=> SELECT 2 + 2; ?column?
🌐
Neon
neon.com › postgresql › getting-started › connect-to-postgresql-database
Connecting to PostgreSQL Database Server
Second, use the psql command to connect to the PostgreSQL server: ... -U postgres: Specify the user that connects to the PostgreSQL server. The -U option means user. Note that you need to use -U in uppercase, not lowercase.
🌐
freeCodeCamp
freecodecamp.org › news › manage-postgresql-with-psql
How to Manage PostgreSQL Databases from the Command Line with psql
October 3, 2025 - So enter psql -d postgres -U postgres to connect to the postgres database as the postgres superuser. ... You will be prompted for a password. Enter the password you chose when you installed PostgreSQL on your computer.
🌐
w3resource
w3resource.com › PostgreSQL › connect-to-postgresql-database.php
Connect to PostgreSQL Database on Linux, Windows | w3resource
April 1, 2026 - It enables you to type in queries ... database using pgAdmin GUI application. Connect to the database at localhost:5432 using the user name postgres and the password supplied....
🌐
KB Hosting
kb.hosting.com › docs › connect-to-postgresql-from-the-command-line
Connecting to PostgreSQL using the command line - hosting.com
To connect to PostgreSQL from the command line, follow these steps: Log in to your account using SSH. At the command line, type the following command. Replace dbname with the name of the database, and username with the database username:
🌐
UbuntuMint
ubuntumint.com › home › postgresql › how to connect to postgres database from command line
How to Connect to Postgres Database From Command Line
December 4, 2023 - $ sudo apt install postgresql-client ... begin, open your terminal and use the psql, a terminal-based front-end to PostgreSQL as follows, where the -d flag is used to specify the database you are connecting to and the -U specifies the username you are connecting as...
Find elsewhere
🌐
W3Schools
w3schools.com › postgresql › postgresql_getstarted.php
PostgreSQL - Get Started
Enter the password you chose when you installed the PostgreSQL database, my password is 12345678: The result might look like an error, but if it shows psql (15.2) or any other version, and in the end you see the postgres=# command (and maybe a warning in between), then you have successfully connected to the database!
🌐
Hevo
hevodata.com › home › learn › database management system
How does PostgreSQL Command line Interface Work?
January 9, 2026 - Now, to get started with psql Connect to database command line you, first have to install PostgreSQL, After installing PostgreSQL, launch psql and enter the following command in the Postgres CLI.
🌐
CommandPrompt Inc.
commandprompt.com › education › how-to-connect-to-postgres-database-server
How to Connect to Postgres Database Server — CommandPrompt Inc.
March 2, 2023 - Provide the superuser password and hit the “OK” button to connect to the Postgres Database Server. Open the Query tool and use any command/query to confirm if the connection is established or not.
Address   2950 Newmarket ST STE 101 - 231, 98226, Bellingham
🌐
Medium
medium.com › cranecloud › connecting-to-a-remote-postgresql-database-779637147abf
Connecting to a remote PostgreSQL database | by Kawere Wagaba | Crane Cloud | Medium
October 7, 2022 - For a local database: psql <dbname> < <infile>. Run these commands at the terminal, not at the psql prompt.
🌐
Tutorial Teacher
tutorialsteacher.com › postgresql › connect-to-postgresql-database
Connect to PostgreSQL Database using SQL Shell & pgAdmin
First, you need to enter the PostgreSQL server name. if it is on your localhost then press Enter. The default value mentioned in the square bracket e.g. [localhost] is the default server.
🌐
Elest
docs.elest.io › books › postgresql › page › connecting-with-psql
Connecting with psql | docs.elest.io
To ensure you're connected correctly, run this command inside the psql prompt: ... version --------------------------------------------------------------------------------------------------------------------- PostgreSQL 16.8 (Debian 16.8-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit (1 row)
🌐
DigitalOcean
docs.digitalocean.com › connect to postgresql cluster
How to Connect to PostgreSQL Database Clusters | DigitalOcean Documentation
1 week ago - Connection string: Pass the connection string from the Control Panel in quotes to psql. Replace <your-username>, <your-password>, <path-to-ca-certificate>, and <your-cluster-hostname>: psql "postgresql://<your-username>:<your-password>@<you...
🌐
PostgreSQL
postgresql.org › docs › 9.1 › app-psql.html
PostgreSQL: Documentation: 9.1: psql
October 27, 2016 - Establishes a new connection to a PostgreSQL server. The connection parameters to use can be specified either using a positional syntax, or using conninfo connection strings as detailed in Section 31.1. Where the command omits database name, user, host, or port, the new connection can reuse ...
🌐
How to Use Linux
howtouselinux.com › home › how to use psql: a comprehensive guide to postgresql’s command-line client
How to Use psql: A Comprehensive Guide to PostgreSQL’s Command-Line Client - howtouselinux
January 4, 2026 - Authentication: Uses peer authentication (trusts OS users matching PostgreSQL users) defined in pg_hba.conf. For explicit control, use flags to define connection details: # Basic syntax: psql -U <user> -d <database> -h <host> -p <port> psql -U postgres -d mydb -h localhost -p 5432
🌐
AlexHost
alexhost.com › home › faq › administration › how to connect to a postgresql database: complete guide for all methods
How to Connect to a PostgreSQL Database: Complete Guide for All Methods
3 weeks ago - Windows: Open Command Prompt, PowerShell, or Windows Terminal. Ensure the PostgreSQL bin directory is added to your system PATH. ... -h host — The server's hostname or IP address (e.g., localhost for local, or a remote IP such as 192.168.1.100). -p port — The port PostgreSQL is listening on (default: 5432). -U username — The PostgreSQL username to authenticate as. -d database — The name of the database you want to connect to.