PL/pgSQL and Security

By default, a PL/pgSQL function executes with the privileges of the user that calls it. That's safe because an unprivileged user won't gain extra privileges simply by calling a PL/pgSQL function. However, there are times when you may want to convey extra privileges to a function. For example, you might hide sensitive information (such as payroll data) from a clerical user, but you want that user to “close the books” at the end of each month. Presumably, the close_the_books() function can do its work without exposing secret data to the user. If that's the case, you can tell PostgreSQL that you want the close_the_books() function to inherit the privileges of the author of the function. To convey extra privileges to a function, ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.