2

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"

6
  • The password you need to enter is the password you have configured for your Laravel connection in your app. Commented Oct 5, 2017 at 2:53
  • DB_HOST=127.0.0.1 DB_PORT=54320 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret @CraigRinger Commented Oct 5, 2017 at 3:00
  • 1
    The notable difference here is the port. You haven't specified a port in your psql command and PostgreSQL's default port is 5432. You must have multiple PostgreSQL instances. What if you add -p 54320 to your command line? Commented Oct 5, 2017 at 3:06
  • yes, you're right. It thinks that homestead is using port 5432, that's why it won't connect. But do you know how to implement postgreSQL in homestead? I can't migrate my database @CraigRinger Commented Oct 5, 2017 at 3:18
  • 1
    I would suggest you sudo su - postgres connecting to psql as Os user: psql -w setting the password to secret for user homestead if such user exists and trying again... Commented Oct 5, 2017 at 6:11

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

6 Comments

where is the path that I should run pc_ctl reload?
Good question! :) Try /usr/lib/postgresql/9.6/bin/
I got this error pg_ctl: no database directory specified and environment variable PGDATA unset
SO has answers to that problem in the following links: Where does PostgreSQL store the database? and How to restart PostgreSQL server on MacOS? (never mind that that is for MacOS, the top answer is a solution to finding the working directory)
Thankyou ffor the reference.
|
3

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";

1 Comment

Is posgtres a typo here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.