Common SQL Errors

PostgreSQL privilege_not_revoked Error Code 1006 Explained

August 4, 2025

REVOKE failed because the specified privilege had not been granted to the role.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is PostgreSQL error privilege_not_revoked (code 1006)?

PostgreSQL Error 1006 privilege_not_revoked appears when a REVOKE command targets a privilege the role never had. Verify existing grants with psql's \dp or pg_catalog queries, then remove or correct the REVOKE statement to match actual privileges.

Error Highlights

Typical Error Message

PostgreSQL Error 1006

Error Type

Permission Error

Language

PostgreSQL

Symbol

privilege_not_revoked

Error Code

1006

SQL State

Explanation

Table of Contents

What is PostgreSQL error privilege_not_revoked (code 1006)?<\/h2>

PostgreSQL raises error 1006 privilege_not_revoked when you issue a REVOKE statement for a privilege the specified role does not currently hold. The server cannot remove what is not there, so execution stops.<\/p>

The error usually surfaces during automated permission clean-ups, migration scripts, or manual privilege audits. Fixing it quickly keeps deployment pipelines green and permissions accurate.<\/p>

What Causes This Error?<\/h3>

Most cases trace back to mismatched GRANT and REVOKE statements.

Scripts assume a previous GRANT ran, but it was skipped or executed on a different environment. The subsequent REVOKE therefore fails.<\/p>

A second trigger is object recreation. Dropping and re-creating a table clears its ACL. Any later REVOKE aimed at the old ACL rows will fire the 1006 error.<\/p>

How to Fix PostgreSQL Error 1006 privilege_not_revoked<\/h3>

Start by confirming the role’s current privileges with \dp or a pg_catalog query.

If the privilege is missing, remove the REVOKE line or guard it with IF EXISTS logic available since PostgreSQL 15.<\/p>

When the privilege should exist, GRANT it first and then REVOKE, or adjust the migration order so the REVOKE runs only after the GRANT in every environment.<\/p>

Common Scenarios and Solutions<\/h3>

Continuous integration scripts that run GRANT commands only on new databases often miss staging and prod drifts.

Add explicit GRANT checks before each REVOKE to stop false alarms.<\/p>

Infrastructure-as-code tools may drop and recreate tables. Tie REVOKE statements to change detection hooks so they execute only on persistent objects.<\/p>

Best Practices to Avoid This Error<\/h3>

Audit privileges regularly with automated reports stored in version control.

Differences highlight drift before REVOKE scripts fail.<\/p>

Use conditional syntax in PostgreSQL 15+: REVOKE SELECT ON TABLE my_table FROM role IF EXISTS;<\/code> to silence harmless revocations while still catching real issues on older versions.<\/p>

Related Errors and Solutions<\/h3>

Error privilege_not_granted fires on failed GRANT statements. Its fix path mirrors 1006: verify existing ACLs first.<\/p>

Error undefined_table occurs when REVOKE targets a table that no longer exists. Ensure object lifecycles align with permission scripts.<\/p>.

Common Causes

Related Errors

FAQs

Is privilege_not_revoked a critical error?<\/h3>No data is lost, but your deployment or migration halts. Fix promptly to keep CI pipelines green.<\/p>

Can I safely ignore this error?<\/h3>If you intentionally revoke nonexistent privileges, upgrade to PostgreSQL 15 and use IF EXISTS to silence it safely.<\/p>

Does Galaxy help avoid this error?<\/h3>Yes. Galaxy’s AI copilot autocompletes accurate GRANT and REVOKE pairs and flags mismatches during review, reducing 1006 incidents.<\/p>

Which PostgreSQL versions support REVOKE IF EXISTS?<\/h3>PostgreSQL 15 and later add the IF EXISTS clause for REVOKE and GRANT commands.<\/p>

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo