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 Overflowcmd - How to connect to PostgreSQL through CLI? - Stack Overflow
postgresql - How do I specify a password to 'psql' non-interactively? - Stack Overflow
connect to postgres database command line linux with password
Access postgresql server on Linux command line, but not GUI (beekeeper)
Videos
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
psql -h <hostname> -U <username> -d <dbname>
If all params are correct then it will ask you for db password for username entered earlier.
Set the PGPASSWORD environment variable inside the script before calling psql:
PGPASSWORD=pass1234 psql -U MyUsername myDatabaseName
For reference, see https://www.postgresql.org/docs/current/static/libpq-envars.html
Since Postgres 9.2 there is also the option to specify a connection string or URI that can contain the username and password. The syntax is:
$ psql postgresql://[user[:password]@][host][:port][,...][/dbname][?param1=value1&...]
Using that is a security risk because the password is visible in plain text when looking at the command line of a running process e.g. using ps (Linux), ProcessExplorer (Windows), or similar tools.
See also this question on Database Administrators
From the official documentation:
psql
It is also convenient to have a
~/.pgpassfile to avoid regularly having to type in passwords. See Section 30.13 for more information.
30.13. The Password File
This file should contain lines of the following format:
hostname:port:database:username:passwordEach of the first four fields can be a literal value, or *, which matches anything. The password field from the first line that matches the current connection parameters will be used.
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