At the start I want to point that I am not and I never was database administrator. I have got experience and knowledge about PL/SQL
and SQL
but so far each database i get touch with was max 50 tables and looking for relation between entities wasn't that hard even if I made it manually.
Problem comes now, when I have got database
which have over 300 tables finding relation between entities is not so easy.
Let imagine table:
table person (
id serial PRIMARY KEY NOT NULL,
name varchar(45)
)
and automaticly i have sequence:
person_id_seq
Can you please tell me if there is any command which return me tables which are using person_id_seq
?
See pg_depend.
select *, pg_describe_object(classid, objid, objsubid)
from pg_depend
where refobjid = 'person_id_seq'::regclass
klin's answer - use pg_depend
is entirely sensible, and a sane way to do this.
I strongly recommend that you try a tool like SchemaSpy to produce database maps and visualisations. It will help a lot, and give you a chance to get an overview of the relationships, not just explore them piece by piece.
If you need to make your query portable then you can use the information_schema
instead of PostgreSQL-specific catalog tables. This query produces a list of foreign key relationships portably - the query was written for MS SQL Server, but is fine on PostgreSQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With