Solved

dependency tree of tables in PostgreSQL

Posted on 2014-04-23
4
1,042 Views
Last Modified: 2014-04-25
Hello Experts

how can I get the list of the postgresql tables in order of dependency tables.
Problem: I need to make a  migration routine of data from one oracle database to PostgreSQL. The data model is equal.
0
Comment
Question by:alcionebernardi
  • 2
4 Comments
 
LVL 3

Expert Comment

by:bayoubeast
ID: 40019058
In psql you could do something like this:

select '\\d+ '||table_schema||'.'||table_name
from information_schema.tables
order by table_schema,table_name;

Open in new window


And if you run the output from that back into psql that will list the dependencies for each table individually.  You'll probably want to add a where clause for the specific schema you want to look at so you don't get all the postgresql tables.

select '\\d+ '||table_schema||'.'||table_name
from information_schema.tables
where table_schema='public'
order by table_schema,table_name;

Open in new window


Is this kind of what you're looking for?  I'm not quite sure if there's a way to make a single list of tables ordered by dependency.
0
 

Author Comment

by:alcionebernardi
ID: 40020154
Hello,
    for example, two tables: d_m_transaction and m_transaction. d_m_transaction has references to m_transaction. I would like a sql that return the two tables in the following order

m_transaction
d_m_transaction

That way I could run the inserts without any violation of constraints

thanks
0
 
LVL 4

Accepted Solution

by:
Alex Matzinger earned 500 total points
ID: 40020660
The easiest way to do this, is to drop the constraints/foreign keys from the tables in your postgres database, import the data (from oracle to postgres) and then re-add the constraints to the tables.  

Otherwise you will need to go by hand through each of your tables and list them in the order they will need to be.  There is no automatic way of listing tables by their constraints.
0
 
LVL 3

Expert Comment

by:bayoubeast
ID: 40020733
Yeah, that's probably the best way to do this.  If you're using ora2pg it has some options for this.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now