Solved

dependency tree of tables in PostgreSQL

Posted on 2014-04-23
4
1,138 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help decide on technology stack 3 104
How to treat the way PHP presents a DB error? 4 120
Whats the correct entry into pg_hba.conf  file 12 106
vcenter 6 u2 install question 1 119
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

827 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