How would you use SQL GRANT and REVOKE commands to secure a microservice's access to a database following the principle of least privilege?

Last updated 3 July 2026

  • Give each microservice its own dedicated database role, never the shared owner/superuser account, to limit blast radius if credentials leak.

  • Use GRANT for only the needed verbs on needed tables (e.g. SELECT only for a reader). Avoid GRANT ALL and DDL rights like CREATE/DROP.

  • Use REVOKE to strip broad defaults (such as Postgres PUBLIC grants). Prefer column-level grants or views to hide sensitive fields.

  • https://reintech.io/blog/sql-grant-and-revoke-statements-guide
  • https://dev.to/felipecezar01/mastering-dcl-the-ultimate-guide-to-grant-and-revoke-in-sql-4hl9
  • https://techcommunity.microsoft.com/blog/azuresqlblog/security-the-principle-of-least-privilege-polp/2067390
  • https://servercake.in/guides/postgresql-for-production/least-privilege-roles
  • https://www.postgresql.org/docs/9.1/sql-grant.html
  • https://www.postgresql.org/docs/current/sql-revoke.html
  • https://blogs.oracle.com/mysql/using-the-mysql-set-role-to-enforce-least-privilege-principles
  • https://medium.com/@srinivas08raghavan/applying-principle-of-least-privilege-to-databases-3ee6a959c079
All SQL interview questions