Search code examples
postgresqlpostgresql-9.2ubuntu-12.10

Postgresql initial configuration: How to access as the postgres user?


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?


Solution

  • 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.