12 VDC battery supply with automatic 12 VDC adapter override
simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. Using a relay to disconnect battery when mains present.


BAT1 supplies the load when the mains is off.
D1 prevents backfeed from the battery to the relay coil (which would disconnect the battery).
When the mains supply, V1, turns on RLY is energised, BAT1 is disconnected and the load is powered via D1.


Be aware that when the power fails that RLY1 may not switch off until V1 falls to 4 or 5 V. This means that the load will be pretty much unpowered until the relay drops out. There are two solutions:


Add some big electrolytics in parallel with the load to maintain voltage during the transition.
Use a 5 or 6 V relay fed via a Zener diode (D3). The relay should drop out at about 3 V which, with the Zener diode, will cause it to drop out when V2 falls to about 9 V.