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 OverflowPhoenixNAP
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.
Videos
01:31
How to connect PostgreSQL database, List schemas and show list ...
12:05
Connecting to the PostgreSQL Database | SQL Fundamentals with ...
04:57
How To Connect/Register PostgreSQL Database Server || PostgreSQL ...
05:26
How To Connect To PostgreSQL Database Using PSQL By Manish Sharma ...
04:40
How to connect to postgres database on windows 10 using CMD in ...
04:27
Set up a local PostgreSQL Database on macOS - YouTube
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?
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:
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!
Top answer 1 of 3
38
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
2 of 3
5
psql -h <hostname> -U <username> -d <dbname>
If all params are correct then it will ask you for db password for username entered earlier.
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.
Call +1-503-667-4564
Address 2950 Newmarket ST STE 101 - 231, 98226, Bellingham
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)
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 ...
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.