I'm setting up my PostgreSQL 9.1. I can't do anything with PostgreSQL: can't createdb
, can't createuser
; all operations return the error message
Fatal: role h9uest does not exist
h9uest
is my account name, and I sudo apt-get install
PostgreSQL 9.1 under this account.
Similar error persists for the root
account.
Users, groups, and roles are the same thing in PostgreSQL, with the only difference being that users have permission to log in by default. The CREATE USER and CREATE GROUP statements are actually aliases for the CREATE ROLE statement.
You can create new roles from the command line with the createuser command. Using the --interactive flag will prompt you for the name of the new role and also ask whether it should have superuser permissions. Logged in as the postgres account, you can create a new user by typing: createuser --interactive.
CREATE ROLE adds a new role to a PostgreSQL database cluster. A role is an entity that can own database objects and have database privileges; a role can be considered a “user”, a “group”, or both depending on how it is used.
SELECT rolname FROM pg_roles; The psql program's \du meta-command is also useful for listing the existing roles.
Use the operating system user postgres
to create your database - as long as you haven't set up a database role with the necessary privileges that corresponds to your operating system user of the same name (h9uest
in your case):
sudo -u postgres -i
As recommended here or here.
Then try again. Type exit
when done with operating as system user postgres
.
Or execute the single command createuser
as postgres
with sudo
, like demonstrated by drees in another answer.
The point is to use the operating system user matching the database role of the same name to be granted access via ident
authentication. postgres
is the default operating system user to have initialized the database cluster. The manual:
In order to bootstrap the database system, a freshly initialized system always contains one predefined role. This role is always a “superuser”, and by default (unless altered when running
initdb
) it will have the same name as the operating system user that initialized the database cluster. Customarily, this role will be namedpostgres
. In order to create more roles you first have to connect as this initial role.
I have heard of odd setups with non-standard user names or where the operating system user does not exist. You'd need to adapt your strategy there.
Read about database roles and client authentication in the manual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With