Hi,
In this schematic I use LEDs as load. When I unplug the power supply from 220V I have a fast blink in LEDs(a delay to switch over battery) but when I disconnect the 5V(VCC) there is no problem and battery switch immediately. With Scope I see voltage decreasing over the gate of the mosfet and maybe the curve making this problem. Is there any way to solve it?
You may need to use a comparator to get a clean switch-over like in the circuit below. As mentioned, the filter caps in the 5 V supply hold the gate high for some time.
R2 provides a bit of hysteresis feedback so that any noise into the circuit won't cause it to oscillate around the switching point. If you leave it out, you may not notice anything unless you look with a scope on VF2 for any signs of multiple transitions at the time of switching. The circuit will still function without this.