If I have two passports with different numbers can I stay 90 days in a country, leave for a few days and return for another 90 days with my second passport? Is my information stored in some database or do they just check your passport stamps? I am asking about visiting Ukraine specifically
It may depend on the country you're visiting, but in general the answer is no. Immigration rules typically apply to each traveler as a person, not to the document. Using different documents may make it more difficult for authorities to identify someone who has overstayed or entered improperly, but the fact that the traveler's periods of stay may be difficult to link does not imply that the traveler's stays in the country comply with its rules.
In addition to passport numbers, passports may be matched by other data, such as name, date of birth, and place of birth. Furthermore, passports lately include biometric information such as fingerprints, which almost always includes a digitized copy of the traveler's image. Immigration authorities can also use these biometrics to match different passports to one another.