Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:27:48+00:00 2026-05-29T16:27:48+00:00

I have 3 roles: superuser, poweruser and user. I have table data and functions

  • 0

I have 3 roles: superuser, poweruser and user. I have table “data” and functions data_select and data_insert.

Now I would like to define, that only superuser can access table “data”. Poweruser and user can not access table “data” directly, but only through the functions.

User can run only function data_select, poweruser can run both data_select and data_insert.

So then I can create users alice, bob, … and inherits them privileges of user or poweuser.

Is this actually achievable? I am fighting with this for the second day and not getting anywhere.

Thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:27:50+00:00Added an answer on May 29, 2026 at 4:27 pm

    Yes, this is doable.

    “superuser” could be an actual superuser, postgres by default.
    I rename the role for plain users to usr, because user is a reserved word – don’t use it as identifier.

    CREATE ROLE usr;
    CREATE ROLE poweruser;
    GRANT usr TO poweruser;  -- poweruser can do everything usr can.
    
    CREATE ROLE bob PASSWORD <password>;
    GRANT poweruser TO bob;
    
    CREATE ROLE alice PASSWORD <password>;
    GRANT usr TO alice;
    
    REVOKE ALL ON SCHEMA x FROM public;
    GRANT USAGE ON SCHEMA x TO usr;
    
    REVOKE ALL ON TABLE x FROM public;
    REVOKE ALL ON TABLE y FROM public;
    
    CREATE FUNCTION
      ...
    SECURITY DEFINER;
    
    REVOKE ALL ON FUNCTION ... FROM public;
    GRANT EXECUTE ON FUNCTION a TO usr;
    GRANT EXECUTE ON FUNCTION b TO poweruser;
    

    Or you could create daemon roles with no login to own the functions and hold the respective rights on the table. That would be even more secure.

    If you are going this route, you will love ALTER DEFAULT PRIVILEGES (introduced with PostgreSQL 9.0). More details in this related answer.

    Read the chapter Writing SECURITY DEFINER Functions Safely in the manual.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am modifying my PHP network's code to have user roles like wordpress here
I have a table of Users that includes a bitmask of roles that the
I have an application that needs to hit the ActiveDirectory to get user permission/roles
We have an ASP.NET application that manages it's own User, Roles and Permission database
I have a login script that verifies a username/password against data in a 'user'
Alright I have two roles setup in Devise: User and Employer. Right now you
Using Resque and Devise, i have roles for User, like: User.first.role #=> admin User.last.role
I have IAuthorizationFilter filter that checks for specific roles. In case user doesn't have
What options do I have to read the roles of the current user from
I have successfully implemented Forms Authentication in SSRS, so it now uses both Roles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.