P
P
prostranstvovremya2019-02-21 15:05:26
PostgreSQL
prostranstvovremya, 2019-02-21 15:05:26

How to create a database on behalf of a role whose name does not match the user in Linux?

To create a database on behalf of a role, you must first enter this role. To enter the role, you must either have a Linux account with a name corresponding to the role in the database, or specify:
> psql -U rolename -h 127.0.0.1 -d databasename,
where databasename is the name of a non-existent database that I just want to create from this user. Without this option (psql -U rolename -h 127.0.0.1) I get:
> psql: FATAL: database "eighthost" does not exist.
I know that there is a way to create a database through the postgres role and assign my new role as OWNER, or create a user in Linux with the role name and log in using identical authentication, but to expand and better understand the issue, I decided to find out:
Is it possible to authorize in PostgreSQl under a new role without a created database and without an account under Linux?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-02-21
@prostranstvovremya

The OS account has nothing to do with the database user. The base can be configured to authenticate a user by matching the username - peer for unix sock. But this is not necessary and this is the only thing that can connect the OS user and the database. (except for the owner's account, which has direct access to the files)
But the database user must already exist. And since you need to create a user first, then create a database for him at the same time.
Further, it should be said that an ordinary user cannot create databases at all. This right must be explicitly granted.
You can connect to postgresql only to a specific existing database, and your user must have the right to both authenticate using the method specified in hba and the right to connect to the desired database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question