How to merge two firebird databases?

199 views
Skip to first unread message

Oliver Weinheimer

unread,
Feb 28, 2024, 6:05:33 AM2/28/24
to firebird-support
How to merge two firebird databases DB1 and DB2? Version of both is 3.0.10, structure/tables of the databases is identical - is there a standard way to merge the contents of both databases or copy contents of DB1 into DB2.

Dimitry Sibiryakov

unread,
Feb 28, 2024, 6:38:32 AM2/28/24
to firebird...@googlegroups.com
There is no such things as "a standard Firebird database" so there is no
standard way to merge them either. Depending on database structure (mainly PK
generation) the way can vary from simple data pump to very custom routines.

--
WBR, SD.

Elmar Haneke

unread,
Feb 28, 2024, 7:11:18 AM2/28/24
to firebird...@googlegroups.com
How to merge two firebird databases DB1 and DB2? Version of both is 3.0.10, structure/tables of the databases is identical - is there a standard way to merge the contents of both databases or copy contents of DB1 into DB2.

Basically you copy all data from one DB into another (or the data from both DB to an empty third one). A Simple Data pump-Utility might do the Job.

Depending on your Application you should make data in DB1 and DB2 "compatible" to be copied together - what ever that means for your application.



Franky Brandt

unread,
Feb 28, 2024, 7:59:03 AM2/28/24
to firebird-support
Seems simple enough to make a custom application that pumps from source DB to Target DB.
- get list of all tables
- Loop over that list, for each table loop over all records and insert each record in the target db
- But you would have to check if the field is computed or not, a table might have triggers that you might want to disable doing the insertion (all depends on what the trigger does)
- There might a situation where you want to exclude one or more tables from the copying.
- The keyfields of the tables of course cannot have duplicate values, so you might want to use generators for the new value.
Op woensdag 28 februari 2024 om 13:11:18 UTC+1 schreef elmar:

Mark Rotteveel

unread,
Feb 28, 2024, 8:05:35 AM2/28/24
to firebird...@googlegroups.com
On 28/02/2024 13:59, Franky Brandt wrote:
> - The keyfields of the tables of course cannot have duplicate values, so
> you might want to use generators for the new value.

Or you need to merge records from DB1 and DB2, and decide which value
source wins.

Mark
--
Mark Rotteveel

Tomasz Tyrakowski

unread,
Feb 28, 2024, 8:47:03 AM2/28/24
to firebird...@googlegroups.com
And follow all foreign keys without cascades and change the references
on the fly, and after that discover all hidden assumptions about the
data, not reflected in the structure (like: there should always be one
record per month in this table - which may be true for both DB1 and DB2,
but not for DB1+DB2 :) ). And the nightmare just keeps unfolding...
So, unless the databases and the applications feeding them with data are
specifically designed with merging in mind (for example, all tables have
unique "database ID" fields as parts of their PKs and the resulting DB
is read only, used just for reporting), it's a very hard problem to
solve in a general case.
Sorry Oliver, but while it's technically quite easy to do (just stitch
together a Python script, selecting data from one connection and
inserting it into another, and doing all that in the right table order
to prevent violation of foreign keys), the success or failure of such
approach depends entirely on the model and the data.
I'm afraid there's no silver bullet.

regards
Tomasz

Message has been deleted

Oliver Weinheimer

unread,
Feb 28, 2024, 10:15:03 AM2/28/24
to firebird-support
Thank you for all the input!
I started a first attempt with the too from clevercomponents.com: DataPump - that worked so far. Now I will try to incorporate a tailor-made solution into my own application.
https://clevercomponents.com/downloads/datapump/
Reply all
Reply to author
Forward
0 new messages