# Dinamically get all database store procedures and viste

**URL:** <https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860>\
**Category:** Python Help\
**Tags:** election\
**Created:** [February 21, 2022, 5:08pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860 "2022-02-21T17:08:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ale123](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@ale123](https://discuss.python.org/u/ale123)\
**Post date:** [February 21, 2022, 5:08pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/1 "2022-02-21T17:08:14Z")

</div>

Hi all,

I have two servers (production and test) with the same databases. Since lots of people is working on them, from time to time I have to check that there is no difference in the created store procedures and viste.

It’s very time consuming, we have lots of DB, I was therefore thinking if there is a dynamic way to load all SPs and viste in a big txt file, one for test and one for prod, to allow easy comparisons.

many thanks for yoyr help!

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [February 21, 2022, 9:49pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/2 "2022-02-21T21:49:20Z")

</div>

There’s usually a command to dump the schemas and procedures from a  
database. You could run that, saving to a text file, then diff against  
the previous copy.

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 21, 2022, 11:08pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/3 "2022-02-21T23:08:25Z")

</div>

Why do you need to check that they are the same?

Instead, just periodically replicate the production database to test, say every night. I expect that a commercial-grade database like Postgres will be able to do that more efficiently than you checking for differences and and then replicating.

[https://wiki.postgresql.org/wiki/Replication,\_Clustering,\_and\_Connection\_Pooling](https://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling)

In this case, you can take the data in the test database as disposable. You never need to copy test back to production, and can _unconditionally_ copy production back to test as often as you want: weekly, daily, continuously.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 21, 2022, 11:12pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/4 "2022-02-21T23:12:50Z")

</div>

Without knowing how Alessandro is currently checking for differences between test and production, how do you know that doing a database dump and text diff is going to be faster that what he is already doing?

Doing a dump of a large database is going to be time consuming, and running diff likewise. Alessandro is asking us to optimise a procedure (determine differences between two databases) without telling us how he is doing it or measuring to see where the bottlenecks are. I think that counts as premature optimization 🙂

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [February 22, 2022, 1:23am UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/5 "2022-02-22T01:23:31Z")

</div>

Steven, if this was aimed at me, I was talking about dumping the schema.  
Not the data.

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 22, 2022, 2:23pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/6 "2022-02-22T14:23:54Z")

</div>

My mistake.

But the question still holds: why not just use replication to keep test  
and production in sync?

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [February 22, 2022, 11:37pm UTC](https://discuss.python.org/t/dinamically-get-all-database-store-procedures-and-viste/13860/7 "2022-02-22T23:37:00Z")

</div>

Surely the point of test is to try things not yet in production? It is  
inherently an environment which will differ from production.

It sounds like the OP has a dynamic test environment and from time to  
time needs to ensure that it is not different from production, or that  
if it is that the changes are as expected.

A regular cron job which dumped the schema and diffed it against the  
previous dump would be silent when things are unchanged and send email  
when the schema changed from the previous run. This, or some similar  
automation, would provide some easy to use system for noticing changes.

Even have a script to do that once, and running it by hand at  
appropriate times would ease the OP’s problem, since it sounds like it  
falls to him to monitor such changes.

Of course, any clarification from allesandro would help.

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)
