Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dependency tree of tables in PostgreSQL

Posted on 2014-04-23
4
Medium Priority
?
1,378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

618 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