简体   繁体   中英

How to login postgreSQL in cmd

I am a laravel user. I run my project with using homestead, and I am using porstgreSQL as my database. I run psql -U homestead -h localhost in my cmd, and then I put secret as my password. But I got an error like this

psql: FATAL: password authentication failed for user "homestead"

For command line, you can try psql -U homestead -W -h localhost , that will force the password prompt.

If this doesn't work, read on...

You might need to look into whether or not the user can access PostgreSQL under that username from the IP you are logging in from. For this, you need to look into the file /etc/postgresql/9.6/main/pg_hba.conf (keeping in mind that the 9.6 is the version, so your directory name might be something like 9.1 or 9.3). In that file, you'll be looking for a line that looks like this:

host all all 127.0.0.1/32 md5

That line states that the IP address 127.0.0.1 can log in via port mask 32 using md5 password hashing. If you need to log in as homestead from, say, port 12.34.56.78, you would need to add this line underneath:

host all homestead 12.34.56.78/32 md5

After making this adjustment, you need to run pg_ctl reload from the command line for the changes to take effect.

Login Postgresql using command line:

psql -U posgtres -p 5432

to show list of database:

\l

to connect database:

\c "database_name"

to show list of table in database:

\dt

or

\dt+

to show list data of table:

SELECT * FROM "table_name";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM