0

How to find user name and password for PostgresSQL on mac? I did not remember that I have set a password and username. How to find the default username and password on mac?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
GuiW
  • 19
  • 3
  • 1
    I don't think there's a universal "default" account; it depends on how you installed PostgreSQL. Postgresql.app is probably different from a Homebrew install which is different from a from-source install, etc. How *did* you install it? Also, notice that PostgreSQL can be configured (in pg_hba.conf) to trust all local connections. If you do that, there's a decent chance that you can connect as postgres, _postgres or your unix username, without a password. – Ture Pålsson Feb 16 '22 at 15:32
  • I update my answer that will fix your issue. – Abdelrhman Mohamed Feb 16 '22 at 16:23

1 Answers1

1

To log in without a password:

sudo -u postgres psql postgres

To know the username

\du

To reset the password:

ALTER USER user_name WITH PASSWORD 'new_password';

replace user_name with your username you found by \du command

  • Is sudo really needed? – OneCricketeer Feb 16 '22 at 15:50
  • @OneCricketeer sure. – Abdelrhman Mohamed Feb 16 '22 at 15:52
  • But this depends on how it was installed. `psql` shouldn't require root permissions, so `su postgres` alone would switch a user account. – OneCricketeer Feb 16 '22 at 15:54
  • @OneCricketeer Yes your right, but before I update my answer It was like `sudo -u user_name psql db_name`, so `user_name` means the username he wants to change his forgotten password, and it will access this user without a password, since he not know the username too I updated just the `user_name` to Postgres and `db_name` to Postgres, and also your solution will work without the `sudo` command. – Abdelrhman Mohamed Feb 16 '22 at 16:19