0

Totally new to postgresql; just had it installed (version 14.1) for the first time via brew on m1 Mac. Installation works fine, but I thought the installation process shall also create a superuser called 'postgres' but when trying to connect to PostgreSql as 'postgres' using sudo -u postgres psql It says unknown user: postgres

What am I missing here?

UPDATE: sorry but forgot to add that I am following a book which uses postgresql version 13; in the book it says after installing via brew it auto creates a superuser 'postgres' which can be used to log in the server in order to create database.

dragonfly02
  • 3,151
  • 32
  • 49

3 Answers3

0

Try to log in with your current user. Here my output

 ~ $ whoami
macbook
 ~ $ psql
psql (13.3)
Type "help" for help.

macbook=# select * from user;
  user
---------
 macbook
(1 row)

macbook=#

So postgresql create macbook user, as my username in system.

I have MacOS Big Sur 11.6 and postgresql13.3.

Eugenij
  • 3,471
  • 1
  • 6
  • 26
  • when I run `psql` it can't connect to the database; it says database 'xxx' doesn't exist where xxx is my username. – dragonfly02 Dec 27 '21 at 01:57
  • @stt106 Try to `psql -d template1`. If get no luck, try to run `createdb` to create DB for your user, then just `psql` [Source](https://stackoverflow.com/questions/17633422/psql-fatal-database-user-does-not-exist) – Eugenij Dec 27 '21 at 06:48
  • It's resolved now, thanks. – dragonfly02 Dec 27 '21 at 07:21
  • @stt106 Happy to help. If this answer or any other one solved your issue, please mark it as accepted. – Eugenij Dec 27 '21 at 07:28
0

"unknown user: postgres" looks like a sudo error message (or a fragment of one), not a PostgreSQL error message. It is complaining about the OS user named postgres, not the database user with the same spelling. You don't know if the database user of that name exists or not, as you haven't gotten far enough to tell.

What the installation method does depends on what the installation method was, which you haven't told us.

jjanes
  • 28,972
  • 5
  • 23
  • 29
0

Just in case this might help others using m1 macOS with version 14.1 postgresql. After installing with brew, simply run

brew services start postgresql
psql postgres

to connect to the server. The book I am reading used version 13 and according to the book installing via brew will auto create a superuser postgres and connect using command sudo -u postgres psql but on version 14.1 this doesn't seem to be the case anymore.

dragonfly02
  • 3,151
  • 32
  • 49