Skip to content

Instantly share code, notes, and snippets.

@adamfast
Created August 19, 2010 18:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamfast/538530 to your computer and use it in GitHub Desktop.
Save adamfast/538530 to your computer and use it in GitHub Desktop.
I needed to find info on a sequence that was causing problems with one of our apps, and couldn't find any info online. Here's what I ended up doing.
\d <sequence> wasn't telling me anything except that it did exist. I couldn't find out what was using it in order to determine if it was safe to eliminate.
select oid from pg_class where relname='<sequence>'; # retrieves the internal ID in PostgreSQL
select refobjid from pg_depend where objid = <found_oid>; # retrieve depenencies for the sequence in question.
select relname from pg_class where oid in (<ref_oid1>, # ... if others); # get the names that are linking to it
\d <found_tables> for each item found above - see if there's any mention of the index blowing up.
OR, after figuring this out, I kept working. Here's one query to rule them all:
select relname from pg_class where oid in (select refobjid from pg_depend where objid in (select oid from pg_class where relname='<sequence>'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment