问题
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?
回答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.
回答2:
su - postgres
and after you have been logged in:
createdb mydb
来源:https://stackoverflow.com/questions/15641488/postgresql-initial-configuration-how-to-access-as-the-postgres-user