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 - In this example, the name of the database is template1. Enter the name of the database you want to connect to. ... Use the exit command to leave the postgres Linux command prompt and return to your regular system user:
๐ŸŒ
EnterpriseDB
enterprisedb.com โ€บ postgres-tutorials โ€บ connecting-postgresql-using-psql-and-pgadmin
Connecting PostgreSQL using psql and pgAdmin | EDB
On Linux, you will explicitly need to pass these parameters at the shell: For PostgreSQL: -bash-4.2$ psql -d postgres -U postgres ยท For Advanced Server: -bash-4.2$ psql -d edb -U enterprisedb ยท If connecting to a remote server from any of ...
๐ŸŒ
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?
๐ŸŒ
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 - Before you can log into a remote database, you need to know the name of your target database, the hostname or IP address of the machine it is running on, and the port number the Postgres database server is listening on), and what user name you want to connect as.
๐ŸŒ
w3resource
w3resource.com โ€บ PostgreSQL โ€บ connect-to-postgresql-database.php
Connect to PostgreSQL Database on Linux, Windows | w3resource
April 1, 2026 - Connect to PostgreSQL Database on Linux, Windows: This tutorial shows you various ways to connect to PostgreSQL database on different platform by using interactive terminal program called psql and pgAdmin GUI application.
๐ŸŒ
Reddit
reddit.com โ€บ r/postgresql โ€บ access postgresql server on linux command line, but not gui (beekeeper)
r/PostgreSQL on Reddit: Access postgresql server on Linux command line, but not GUI (beekeeper)
August 9, 2023 -

I don't expect anyone to be familiar with beekeeper, however, I'm hoping that maybe there are some common threads to this issue, via other GUIs as well.

I use this command to get into the postgres server as user postgres ( I think ) on command line:

sudo -i -u postgres psql

I'm prompted for my user password (one I use to get into computer), however, I'm not prompted for any other password, like one specifically for the database.

when I use the same info for my GUI (beekeeper studio), I get this:

connect ECONNREFUSED 127.0.0.1:5432

all i need is to access it myself on the localhost. Oddly I''m able to access the postgres database as user postgres on the same GUI, on my Apple running OS 11. I do require a password for that database, that I set myself, but it was so long ago,that I don't remember how or why I created a password for the default postgres db.

It might help to explain that I may be an unconventional poster here, since I'm not a dba nor do I have dba knowledge. I used to be just another Microsoft SQL admin user, at my last couple jobs, running basic queries and whatnot. The type of employee who had to submit a ticket to a dba, to update a table for any reason. I found that I preferred SQL for organizational tasks, that most consumers use spreadsheet applications for, so I found postgresql and the GUI Beekeeper, to basically recreate my Microsoft SQL admin experience, on my Apple OS ( and now Linux ) at home. I expect I need to provide more information, please let me know, thank you

๐ŸŒ
Yolinux
yolinux.com โ€บ TUTORIALS โ€บ LinuxTutorialPostgreSQL.html
YoLinux Tutorial: The PostgreSQL Database and Linux
Connect to the database: /usr/bin/psql bedrock Execute command as Linux user postgres You will now be at the PostgreSQL command line prompt. [prompt]$ psql - or "psql bedrock" Welcome to psql, the PostgreSQL interactive terminal.
Find elsewhere
๐ŸŒ
Super User
superuser.com โ€บ questions โ€บ 1432817 โ€บ how-to-connect-to-a-postgresql-database
linux - How to connect to a PostgreSQL database? - Super User
May 4, 2019 - Does anyone know how this relates to a Postgre database? Where exactly is it located? If one wants to connect to a database using psql, it is necessary to know the name of the database. But how? Would appreciate some help. ... The database is in /etc/postgresql/9.6/main, but I guess you don't want to "download" it, but instead want a "dump" of the database.
๐ŸŒ
Reddit
reddit.com โ€บ r/postgresql โ€บ how can i setup psql command line client to connect to a non-superuser database in linux mint 21.3/ubuntu 22.04?
r/PostgreSQL on Reddit: How can I setup psql command line client to connect to a non-superuser database in Linux Mint 21.3/Ubuntu 22.04?
January 31, 2024 - Find out what shell you're using. If it's bash, you can add something like this to your .bash_profile: export PGHOST=localhost export PGUSER=testuser export PGDATABASE=testuser ยท And from then on, you can simply connect with psql and no parameters at all.
๐ŸŒ
Linux Tip
linuxscrew.com โ€บ home โ€บ programming โ€บ databases โ€บ how to connect to postgresql from the linux command line
How to Connect to PostgreSQL from the Linux Command Line
July 24, 2023 - Unless you are logged in as the user postgres and connecting to localhost, you will most likely need to specify the username (-U) and ask to be prompted for a password (-W) to connect: psql -h localhost -p 5432 -U user_name -W -d database_name ...
๐ŸŒ
Micro Focus
microfocus.com โ€บ documentation โ€บ idol โ€บ IDOL_12_6 โ€บ MediaServer_12.6_Documentation โ€บ Guides โ€บ html โ€บ Content โ€บ Getting_Started โ€บ Configure โ€บ PostgreSQL_Setup_Linux.htm
Set Up a PostgreSQL Database on Linux - Micro Focus
Edit the configuration file pg_hba.conf, to allow your Media Server to connect to the database. Create a new database to store Media Server training data and set up the database schema that Media Server requires. To set up the schema, run the postgres.sql script provided in the sql folder of the Media Server installation directory.
๐ŸŒ
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:
๐ŸŒ
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.
๐ŸŒ
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 - The psql command-line tool is the ... the preferred tool for system administrators and power users. Linux / macOS: Open your terminal application....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ manage-postgresql-with-psql
How to Manage PostgreSQL Databases from the Command Line with psql
October 3, 2025 - If you want to directly connect to a database as yourself (rather than as the postgres superuser), enter your system username as the username value. Launch the psql application โ€“ it'll be called "SQL Shell (psql)". You will be prompted for ...
๐ŸŒ
Ubuntu
ubuntu.com โ€บ server โ€บ docs โ€บ how-to โ€บ databases โ€บ install-postgresql
Install and configure PostgreSQL - Ubuntu Server documentation
3 weeks ago - The above command connects to PostgreSQL database template1 as user postgres. Once you connect to the PostgreSQL server, you will be at an SQL prompt.
๐ŸŒ
Silverspringenergy
silverspringenergy.com โ€บ logging-in-to-postgresql-database-on-linux-terminal
Logging in to PostgreSQL database on Linux terminal โ€“ Silver Spring Energy Consulting Ltd.
April 11, 2019 - The server used in this section is running Ubuntu Linux 18.10. ... If you are the database administrator and need access to the root PostgreSQL user account, the method is slightly different. ... Once logged in as postgres, it is possible to log into the PostgreSQL database cluster and connect to your database to make alterations as needed.
๐ŸŒ
Hevo
hevodata.com โ€บ home โ€บ learn โ€บ database management system
How does PostgreSQL Command line Interface Work?
January 9, 2026 - Replace <hostname>, <port>, <username>, and <database> with your specific values. -h: Specifies the host where the PostgreSQL server is running. Use localhost if itโ€™s on the same machine. -p: Specifies the port number. The default is 5432. -U: Specifies the username you want to connect with.
๐ŸŒ
NTU Singapore
www3.ntu.edu.sg โ€บ home โ€บ ehchua โ€บ programming โ€บ sql โ€บ PostgreSQL_GetStarted.html
Getting Started with PostgreSQL
-- List all databases via \l (or \list), or \l+ for more details postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- mytest | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | ...... -- By default, CREATE DATABASE copies the "template1", which you could customize. -- "template0" has the same contents as "template1", but you should not change. -- Connect to mytest database via \c (or \connect) -- Take note of the change of database name in the command prompt.