pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to determine what is preventing deleting a rule
3+ messages / 3 participants
[nested] [flat]

* How to determine what is preventing deleting a rule
@ 2019-08-17 23:37 stan <stanb@panix.com>
  2019-08-17 23:49 ` Re: How to determine what is preventing deleting a rule Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: stan @ 2019-08-17 23:37 UTC (permalink / raw)
  To: pgsql-general


I created some roles that I think are badly named, as my understanding of
them increases.

I have deleted,  what i thought were all the objects referenced by these roles,
but I still get an error saying there is one object they reference.

How can I find out what this object is?


-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to determine what is preventing deleting a rule
  2019-08-17 23:37 How to determine what is preventing deleting a rule stan <stanb@panix.com>
@ 2019-08-17 23:49 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-08-18 00:06   ` Re: How to determine what is preventing deleting a rule Melvin Davidson <melvin6925@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2019-08-17 23:49 UTC (permalink / raw)
  To: stan <stanb@panix.com>; +Cc: pgsql-general

stan <stanb@panix.com> writes:
> I have deleted,  what i thought were all the objects referenced by these roles,
> but I still get an error saying there is one object they reference.
> How can I find out what this object is?

The error should tell you, if you're connected to the database where
that object is.

regression=# create database d1;
CREATE DATABASE
regression=# create database d2;
CREATE DATABASE
regression=# create user joe;
CREATE ROLE
regression=# \c d2 joe
You are now connected to database "d2" as user "joe".
d2=> create table tt(d1 int);
CREATE TABLE
d2=> \c d1 postgres
You are now connected to database "d1" as user "postgres".
d1=# drop user joe;
ERROR:  role "joe" cannot be dropped because some objects depend on it
DETAIL:  1 object in database d2
d1=# \c d2
You are now connected to database "d2" as user "postgres".
d2=# drop user joe;
ERROR:  role "joe" cannot be dropped because some objects depend on it
DETAIL:  owner of table tt

Unfortunately, we can't see into the catalogs of a different database
to explain about dependencies there ...

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: How to determine what is preventing deleting a rule
  2019-08-17 23:37 How to determine what is preventing deleting a rule stan <stanb@panix.com>
  2019-08-17 23:49 ` Re: How to determine what is preventing deleting a rule Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-18 00:06   ` Melvin Davidson <melvin6925@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Melvin Davidson @ 2019-08-18 00:06 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: stan <stanb@panix.com>; pgsql-general

> How can I find out what this object is?
This query might help if the object is a table:

SELECT c.relname as table,
       a.rolname as owner,
       c.relacl as permits
  FROM pg_class c
  JOIN pg_authid a ON ( a.OID = c.relowner )
WHERE relname NOT LIKE 'pg_%'
  AND relname NOT LIKE 'information%'
  AND relname NOT LIKE 'sql_%'
  AND relkind = 'r'
  AND a.rolname = '<the_owner_with_problem>'
ORDER BY relname;

Since you have not stated the PostgreSQL version, I can only
assure you this will work for 9.6 and below.

On Sat, Aug 17, 2019 at 7:49 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> stan <stanb@panix.com> writes:
> > I have deleted,  what i thought were all the objects referenced by these
> roles,
> > but I still get an error saying there is one object they reference.
> > How can I find out what this object is?
>
> The error should tell you, if you're connected to the database where
> that object is.
>
> regression=# create database d1;
> CREATE DATABASE
> regression=# create database d2;
> CREATE DATABASE
> regression=# create user joe;
> CREATE ROLE
> regression=# \c d2 joe
> You are now connected to database "d2" as user "joe".
> d2=> create table tt(d1 int);
> CREATE TABLE
> d2=> \c d1 postgres
> You are now connected to database "d1" as user "postgres".
> d1=# drop user joe;
> ERROR:  role "joe" cannot be dropped because some objects depend on it
> DETAIL:  1 object in database d2
> d1=# \c d2
> You are now connected to database "d2" as user "postgres".
> d2=# drop user joe;
> ERROR:  role "joe" cannot be dropped because some objects depend on it
> DETAIL:  owner of table tt
>
> Unfortunately, we can't see into the catalogs of a different database
> to explain about dependencies there ...
>
>                         regards, tom lane
>
>
>

-- 
*Melvin Davidson*
*Maj. Database & Exploration Specialist*
*Universe Exploration Command – UXC*
Employment by invitation only!

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-08-18 00:06 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-17 23:37 How to determine what is preventing deleting a rule stan <stanb@panix.com>
2019-08-17 23:49 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-18 00:06   ` Melvin Davidson <melvin6925@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox