Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check role of current PostgreSQL user from Qt application?

Tags:

I have some application based on Qt library and using QPSQL driver.
In PostreSQL defined a few user roles (e.g: admin, operator, user). My application creates a connection to postgres server under specified user. How can I check the users role?

like image 272
Maksim Nesterenko Avatar asked Mar 19 '14 09:03

Maksim Nesterenko


People also ask

How do I see roles in PostgreSQL?

SELECT rolname FROM pg_roles; The psql program's \du meta-command is also useful for listing the existing roles. In order to bootstrap the database system, a freshly initialized system always contains one predefined role.

Is role same as user in postgres?

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.

What is role name in PostgreSQL?

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

Where are roles stored in PostgreSQL?

Roles are stored in the pg_authid catalog, which is physically stored in the data/global/ subfolder of a PostgreSQL installation, together with the other cluster-wide tables. You can query the contents of pg_authid through the pg_roles view. NOTE: you will need superuser rights to dump the roles.


1 Answers

The manual:

SELECT current_user;  -- user name of current execution context
SELECT session_user;  -- session user name

Meaning, session_user shows the role you connected with, and current_user shows the role you are currently operating with, for instance after calling SET role some_other_role;.

like image 88
Erwin Brandstetter Avatar answered Oct 16 '22 00:10

Erwin Brandstetter