> Roles are global in the entire Postgres system, not scoped to a particular database.
A workaround is the db_user_namespace option
https://www.postgresql.org/docs/current/runtime-config-conne...
> db_user_namespace (boolean)
> This parameter enables per-database user names. It is off by default. This parameter can only be set in the postgresql.conf file or on the server command line.
> If this is on, you should create users as username@dbname. When username is passed by a connecting client, @ and the database name are appended to the user name and that database-specific user name is looked up by the server. Note that when you create users with names containing @ within the SQL environment, you will need to quote the user name.
> With this parameter enabled, you can still create ordinary global users. Simply append @ when specifying the user name in the client, e.g., joe@. The @ will be stripped off before the user name is looked up by the server.
> db_user_namespace causes the client's and server's user name representation to differ. Authentication checks are always done with the server's user name so authentication methods must be configured for the server's user name, not the client's. Because md5 uses the user name as salt on both the client and server, md5 cannot be used with db_user_namespace.
> Note
> This feature is intended as a temporary measure until a complete solution is found. At that time, this option will be removed.
It's a bit concerning that the documentation states that the option is intended to be removed; Postgresql has a ton of misfeatures that, in name of maintaining backwards compatibility, aren't removed just because new, better features are introduced.
However, I suppose that if a better way to scope roles is created, migration tools will be made available