Buenas senhoritos e senhoritas.

Neste pequeno post, vou mostrar como alterar o horário do servidor (Linux) e refletir isto no Oracle. Tarefa que faz muitos administradores odiarem o horário de verão 🙂
Na realidade, partindo da versão 10g pra frente, o Oracle atualiza automaticamente o horário ao se alterar o servidor. Porém para bases 9i ou anteriores, você deverá reiniciar o banco para pegar as alterações.

ALTERANDO O HORÁRIO DO SERVIDOR

No exemplo abaixo, utilizarei o Oracle 10gr2 num Redhat.

Nosso horário:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”U1FMPiBhbHRlciBzZXNzaW9uIHNldCBOTFNfREFURV9GT1JNQVQgPSAnZGQvbW0veXl5eSBISDI0Om1pOnNzJzsKc2VsZWN0IHN5c2RhdGUgZnJvbSBkdWFsOwohZGF0ZQoKU2Vzc2lvbiBhbHRlcmVkLgpTUUw+IApTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMTkvMTAvMjAxMiAxMToxNzozNQpTUUw+IApTZXggT3V0IDE5IDExOjE3OjM1IEVEVCAyMDEy” hover_enabled=”0″]U1FMPiBhbHRlciBzZXNzaW9uIHNldCBOTFNfREFURV9GT1JNQVQgPSAnZGQvbW0veXl5eSBISDI0Om1pOnNzJzsKc2VsZWN0IHN5c2RhdGUgZnJvbSBkdWFsOwohZGF0ZQoKU2Vzc2lvbiBhbHRlcmVkLgpTUUw+IApTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMTkvMTAvMjAxMiAxMToxNzozNQpTUUw+IApTZXggT3V0IDE5IDExOjE3OjM1IEVEVCAyMDEy[/et_pb_dmb_code_snippet]

Observe que o horário está ok tanto no oracle quanto no sistema operacional. Agora, vamos manter a sessão ativa e vamos alterar o horário do servidor.

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”W3Jvb3RAb3JhMSB+XSMgZGF0ZSAtcyAxMjoxMApTZXggT3V0IDE5IDEyOjEwOjAwIEVEVCAyMDEyCkUgYWdvcmEgc2UgZm9ybW9zIG5hIG5vc3NhIHNlc3PDo28gcXVlIGZpY291IGF0aXZhLCB0ZXJlbW9zOgoKU1FMPiBzZWxlY3Qgc3lzZGF0ZSBmcm9tIGR1YWw7CgpTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMTkvMTAvMjAxMiAxMjoxMDoyNwoKU1FMPg==” hover_enabled=”0″]W3Jvb3RAb3JhMSB+XSMgZGF0ZSAtcyAxMjoxMApTZXggT3V0IDE5IDEyOjEwOjAwIEVEVCAyMDEyCkUgYWdvcmEgc2UgZm9ybW9zIG5hIG5vc3NhIHNlc3PDo28gcXVlIGZpY291IGF0aXZhLCB0ZXJlbW9zOgoKU1FMPiBzZWxlY3Qgc3lzZGF0ZSBmcm9tIGR1YWw7CgpTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMTkvMTAvMjAxMiAxMjoxMDoyNwoKU1FMPg==[/et_pb_dmb_code_snippet]

Sem segredo, sem problemas. Neste caso.

Agora vamos a alguns problemas conhecidos de horário no Oracle.

1-ALTERANDO O /ETC/LOCALTIME

Pois bem, quando mudamos nosso localtime para apontar para uma nova zoneinfo, certamente teremos problemas na mudança de horários do Oracle.
Observe o que fiz com meu usuário ROOT:

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”W3Jvb3RAb3JhMSBldGNdIyBsbiAtcyAvdXNyL3NoYXJlL3pvbmVpbmZvL1NpbmdhcG9yZSAvZXRjL2xvY2FsdGltZQpbcm9vdEBvcmExIGV0Y10jIGRhdGUKU8OhYiBPdXQgMjAgMDA6MjA6MzEgU0dUIDIwMTI=” hover_enabled=”0″]W3Jvb3RAb3JhMSBldGNdIyBsbiAtcyAvdXNyL3NoYXJlL3pvbmVpbmZvL1NpbmdhcG9yZSAvZXRjL2xvY2FsdGltZQpbcm9vdEBvcmExIGV0Y10jIGRhdGUKU8OhYiBPdXQgMjAgMDA6MjA6MzEgU0dUIDIwMTI=[/et_pb_dmb_code_snippet]

E como ficou meu usuário no Oracle ( aquele que estava logado )?

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”U1FMPiBhbHRlciBzZXNzaW9uIHNldCBOTFNfREFURV9GT1JNQVQgPSAnZGQvbW0veXl5eSBISDI0Om1pOnNzJzsKc2VsZWN0IHN5c2RhdGUgZnJvbSBkdWFsOwohZGF0ZQpTZXNzaW9uIGFsdGVyZWQuCgpTUUw+IApTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMTkvMTAvMjAxMiAxMjoyMzoxNQoKU1FMPiAKU2V4IE91dCAxOSAxMjoyMzoxNiBFRFQgMjAxMg==” hover_enabled=”0″]U1FMPiBhbHRlciBzZXNzaW9uIHNldCBOTFNfREFURV9GT1JNQVQgPSAnZGQvbW0veXl5eSBISDI0Om1pOnNzJzsKc2VsZWN0IHN5c2RhdGUgZnJvbSBkdWFsOwohZGF0ZQpTZXNzaW9uIGFsdGVyZWQuCgpTUUw+IApTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMTkvMTAvMjAxMiAxMjoyMzoxNQoKU1FMPiAKU2V4IE91dCAxOSAxMjoyMzoxNiBFRFQgMjAxMg==[/et_pb_dmb_code_snippet]

O horário exibido pelo oracle ainda é o antigo.

Como resolver?
Simples, reinicie a aplicação que usa o Oracle. Pois ela está com a config de zona antiga.

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”U1FMPiBTRUxFQ1QgU0VTU0lPTlRJTUVaT05FIEZST00gRFVBTDsKClNFU1NJT05USU1FWk9ORQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KLTA0OjAwCkFww7NzIHJlaW5pY2lhciBvIGFwbGljYXRpdm8gb3UgaW5pY2lhciB1bWEgbm92YSBzZXNzw6NvOgoKU1FMPiBTRUxFQ1QgU0VTU0lPTlRJTUVaT05FIEZST00gRFVBTDsKClNFU1NJT05USU1FWk9ORQotLS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!

É normal alguns administradores exportarem ou copiarem scripts de login ( profile ) entre os servidores. O problema é se o script setar a variável TZ incorretamente.
Observe que no env do usuário oracle, ( aqueeeele que tava logado ) não possuia a variável TZ.

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”W29yYWNsZUBvcmExIGJkdW1wXSQgZW52IHwgZ3JlcCBUWgpbb3JhY2xlQG9yYTEgYmR1bXBdJApBZ29yYSB2YW1vcyBleHBvcnRhciB1bSBUWiBlIHZlciBvIHF1ZSBhY29udGVjZSBjb20gbm9zc28gaG9yw6FyaW86Cgpbb3JhY2xlQG9yYTEgYmR1bXBdJCBleHBvcnQgVFo9J0dNVC0xMCcKW29yYWNsZUBvcmExIGJkdW1wXSQgc3FscGx1cyAtcyAvIGFzIHN5c2RiYQphbHRlciBzZXNzaW9uIHNldCBOTFNfREFURV9GT1JNQVQgPSAnZGQvbW0veXl5eSBISDI0Om1pOnNzJzsKc2VsZWN0IHN5c2RhdGUgZnJvbSBkdWFsOwpTZXNzaW9uIGFsdGVyZWQuCgpTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMjAvMTAvMjAxMiAwMjo0Mjo1Mg==” hover_enabled=”0″]W29yYWNsZUBvcmExIGJkdW1wXSQgZW52IHwgZ3JlcCBUWgpbb3JhY2xlQG9yYTEgYmR1bXBdJApBZ29yYSB2YW1vcyBleHBvcnRhciB1bSBUWiBlIHZlciBvIHF1ZSBhY29udGVjZSBjb20gbm9zc28gaG9yw6FyaW86Cgpbb3JhY2xlQG9yYTEgYmR1bXBdJCBleHBvcnQgVFo9J0dNVC0xMCcKW29yYWNsZUBvcmExIGJkdW1wXSQgc3FscGx1cyAtcyAvIGFzIHN5c2RiYQphbHRlciBzZXNzaW9uIHNldCBOTFNfREFURV9GT1JNQVQgPSAnZGQvbW0veXl5eSBISDI0Om1pOnNzJzsKc2VsZWN0IHN5c2RhdGUgZnJvbSBkdWFsOwpTZXNzaW9uIGFsdGVyZWQuCgpTWVNEQVRFCi0tLS0tLS0tLS0tLS0tLS0tLS0KMjAvMTAvMjAxMiAwMjo0Mjo1Mg==[/et_pb_dmb_code_snippet]

A data passou a ser 2h ao invés de 12.

Como resolver?
Basta remover o TZ ( export -n TZ ) ou setá-lo para refletir seu TIMEZONE atual, ou alterar a variável TIME_ZONE para refletir seu TIMEZONE.

[et_pb_dmb_code_snippet _builder_version=”4.0.6″ code=”YWx0ZXIgc2Vzc2lvbiBzZXQgVElNRV9aT05FPeKAmS0wMzowMOKAsjs=” hover_enabled=”0″]YWx0ZXIgc2Vzc2lvbiBzZXQgVElNRV9aT05FPeKAmS0wMzowMOKAsjs=[/et_pb_dmb_code_snippet]