0

After installing postgresql, I tried it out, typing createdb mydb, like it's written in the documentation. Then the following error occured:

createdb: could not connect to database postgres: FATAL:  role "xxx" does not exist

I studied the documentation, where is said:

You will need to become the operating system user under which PostgreSQL was installed (usually postgres) to create the first user account

I tried this by accessing psql (in my case with sudo -u postgres psql, using Ubuntu 12.10). But then what should I do?

Sascha Mayr
  • 341
  • 4
  • 16

2 Answers2

1

if the db is owned by user postgres you can do the following

createdb -U postgres dbname

since by default postgresql will trust connections from localhost.

Doon
  • 19,719
  • 3
  • 40
  • 44
  • Not working.. Resolving to: createdb: could not connect to database postgres: FATAL: Peer authentication failed for user "postgres" – Sascha Mayr Mar 26 '13 at 16:02
  • 1
    hmm I am guessing whatever you used to install the server modified the default config to not trust. try `sudo su - postgres` and then run the createdb. not sure – Doon Mar 26 '13 at 16:05
0
su - postgres

and after you have been logged in:

createdb mydb
1ac0
  • 2,875
  • 3
  • 33
  • 47