1

I have an application that needs to know if it is connected to the original database that it was installed with or if the connection is to a copy of that database. Is there any known method to know if the database has been cloned and the application is no longer connected to the original? I am specifically interested in MS SQL Server and Oracle.

I was kicking ideas around for a stored procedure but that most likely doesn't have access to the hardware to confirm unique hardware information that would somewhat guarantee that the database is the one that it was originally connected to during installation.

I'm trying to prevent/detect cloning of a database so that there is only 1 "true location of truth".

millebi
  • 161
  • 5

3 Answers3

3

I have cloned Oracle databases for two purposes. To the best of my knowledge only one of these will meet your requirement.

  • I have cloned database to provide an additional instance (sometimes read-only) for another environment or use. In this case I change the database name. These clones can be detected by checking the database name.
  • I have cloned the database for recovery or roll-back purposes. Usually, these replace the original database. I know of no way of identifying this as a cloned database.

There is data that may indicate the database was cloned, or moved. Things like filenames for tablespaces are likely to change when a database is cloned, but they can change even if the database is not cloned. I believe you can retrieve the hostname or IP address on which the database is running. Again, this may be indicative that the database is cloned, but can't be used to verify that it is a clone.

While it is possible to end up connected to the wrong clone, it is generally somewhat difficult to get in that situation. Spend some time understanding how your connections to the database are routed.

BillThor
  • 28,293
  • 3
  • 39
  • 70
1

My take on it is this: if it is made of bits, it can be cloned in a way that you will never be able to tell the difference between the original and the clone. Your only chance would be if there was some sort of a calculated value that each database instance returns, so -

  1. Each database instance returns a different value.
  2. The value returned by each database instance is consistent across invocations.

Condition number (2) is your villain here. If the value returned by each instance is consistent across invocations, then the value must rely on some sort of a stored value, somewhere. That stored value can be cloned, too...

Q.E.D

Isaac
  • 256
0

'show slave status;' you know which server you are connected to...the show slave status will tell you which server is the master...if they are on different servers. You may be able to use the global variable server_id to figure out the difference on the same server...I have not played with it.