Search This Blog

Tuesday, July 29, 2014

oracle tidbits: the trouble with triggers

חיפוש אינטרנטי בענייני אורקל הביא אותי למאמר ישן למדי של טום קייט, שלא נתקלתי בו בזמנו.

מתברר שטום קייט עצמו, בערך עשור אחרי שהדאטה-בייס טריגרס נוספו לאורקל , כתב כתבה שמטילה ספק עצום לגבי רוב השימושים המקובלים בטריגרים. במילותיו של האיש עצמו (שכדרכו, חריף ומדוייק, יודע גם לחזור בתשובה):
Once upon a time, a long time ago, 
 I thought triggers were the coolest thing ever and I used (and abused) them heavily. Now, whenever possible, I will go very far out of my way to avoid a trigger.
וחייבים לתת לו את זה - הוא מאוד משכנע.

זה מזכיר לי המלצה ישנה-נושנה של טום קייט, להשתמש בחידושים שמביא איתו הDB, באחד מספריו, המלצה שתמיד היתה לי איתה בעיה.

לא בגלל שיש לי משהו נגד חידושים, אלא בגלל שבדומה לאנשי תוכנה רבים שיש להם רקע כסיסטם, אני נוטה לחשוד בקוד חדש ולהניח שהחידושים הביאו איתם גם באגים חדשים, ולכן, לפיתוחים שמיועדים להגיע לסביבות פרודקשן בטווח של החצי שנה שאחרי החידוש, מעדיף לחכות.

זו העדפה אישית, וכבר יצא לי להיות חלק מארגונים שבהם נהגו אחרת, לטוב ולרע.
היו סביבות שנהגו במדיניות לה התנגד קייט בזמנו - לעבוד כאילו אתה באורקל 6; היו סביבות שנהגו במדיניות של שדרוג תוך חודשיים אחרי צאתו לשוק. (כל מדיניות מביאה איתה את האתגרים שלה, את היתרונות שלה ואת החסרונות שלה, אבל זה אולי עניין לכתבה אחרת).

המפגש בין ההמלצה על חידושים לעומת ההמלצה לא להשתמש בטריגרים גרמו לי להרהר בחלק מהחידושים של Oracle של השנים האחרונות שאני מאוד לא אוהב. אני מדבר על אפשרויות כמו עמודות נסתרות או חלק מהטכנולוגיות החדשות שמנהלות מאחורי הקלעים מבנים שלמים (זה נכון כמובן גם לגבי אפשרויות שאינן קשורות לקוד, דוגמת ALTER TABLE...SET UNUSED שיש לי חשד שתשאיר אחריה הרבה מאוד מידע שלא נמחק אבל נשכח.)

אותם נימוקים שמשמשים את קייט לעיצוב בסיס-נתונים שמתרחק מטריגרים, יפים לדעתי גם לאפשרויות האלה: אפשרות שאיננה חלק מהקוד הכללי, קל לשכוח אותה, קשה לבקר אותה, והיא פוטנציאל לבאגים לרוב.

Thursday, July 17, 2014

Forgot your linux CentOS root password ? Facing an old linux machine and all passwords lost to oblivion? Have not fear!

Introduction
A friend emailed, confused. We worked on a shared initiative a few years ago, using virtual machines as the development environments. He wants to refresh his memory about something we did there, but alas! he has no recollection of the passwords and thus he can't access the virtual machine. 

After I emailed back with instructions on how to recall the passwords (believing it is better to give a man a fishing rod than a fish), I realized that it was not the first time I answered such a question nor will it be the last, and thought it would be better to compile a short guide for future comfort. 

Preliminary notes
(1) although you can use this technique to gain access to a machine that is not yours, do not do it. Such conduct is immoral and criminal. If you are caught, you will spend jail time. If you are not caught, it does not make you a good person. Be a good human being. There are not enough of these in this world. 
(2) this howto is demonstrated on a CentOS machine. It should work on most linux distributions that use grub as the boot manager. 

How to change root's password if you do not know it?
And now that we all know that we use the following instructions to regain access to machines that we are lawfully allowed to access, lets get into the details: 

1. Reboot the machine. 
2. Press the escape key , to stop the boot and get to the boot menu 


3. Press a (to append the boot entry adding to the end) 
4. add "1" (without the quote marks) or "single" (without the quote marks) at the end of the line. 

5. press enter 
6. The machine shall boot into single user mode


7. change the password of any user you like using passwd, including the root. 
8. reboot. 

More notes (mainly for newbies):
1. as this usually happens to people i know regarding old machines, when all passwords are forgotten, a rather embarrassing situation sometimes occurs. Having changed the root password and rebooting, people return to the graphic entry screen, but then are unable to login thru the graphic interface because of the limitations aimed at preventing working full time as root (limitations which I DO NOT RECOMMEND TO CHANGE). 














the solution for the predicament: if you have root but need to change another user's password, 
when you get to the main boot screen press CTRL+ALT+F2 (or another of the F keys that gets us to console screen); login thru the console screen as root;  passwd the users you need for login thru graphic mode.... ; CTRL+ALT+F1 will return you to the graphic interface. (mostly. in some distributions as far as I recall its CTRL+ALT+F7); and now you can peacefully login... 

2. This solution is required only if root's password is forgotten/unknown. after all, from root (or root group members) you can change anyone else. 

3. Even though the outline suggests that you only change root's password in single user mode, if we are dealing with an ancient relic whose entire password set is forgotten, try to work elegantly and use the opportunity and change whoever is necessary. 

4. in real life, you can't use this to hack into a machine, unless you have physical access to its console. 

5. in general, remember the maxim: "with great power comes a great responsibility".