upgrade – ERROR: permission denied for relation pg_class SQL state: 42501

Trying to execute the below query: but gettting permission denied for pg_class error, tried to grant privileges to all tables, sequences and functions but no grants warnings have been issued. Please help to resolve this. or suggest how to remove usage of reg* datatypes
delete FROM pg_catalog.pg_class as c
using pg_catalog.pg_namespace as n, pg_catalog.pg_attribute as a
WHERE c.oid = a.attrelid
AND NOT a.attisdropped
AND a.atttypid IN (‘pg_catalog.regproc’::pg_catalog.regtype,
AND c.relnamespace = n.oid
AND n.nspname NOT IN (‘pg_catalog’, ‘information_schema’);