Hacker News new | past | comments | ask | show | jobs | submit login

I've gotten into the habit of enabling transactions by default in my .psqlrc. And before I do any maintenance, a good:

abort;

begin;

Just to be doubly sure. Then notice the number of deleted rows, and select from the table afterwards.




I am a bit less convinced by this practice. The general consensus seems to be: "oh you can SELECT around after you've done your update and before you commit; the update." But while you're doing that, you might be holding row locks on all the data your update touched, and meanwhile the lock acquisitions in your app are failing, along with whatever that entails. And if you're not doing that and immediately commit;ing, are you gaining anything?


When the UPDATE or DELETE finishes it will output the number of rows changed. If that number is much larger than expected, something probably went wrong. So there's a gain even if you don't investigate the results in detail.


I agree with parent that using transactions is good practice. In general, naked SQL on a production DB is a bad idea - it is not different to running untested coded in a production environment. Why risk it?

Transactions are a sane safeguard if you absolutely must run SQL on your production database.


[REMOVED]


This is a lot of manual steps. Why not have migration scripts in your code base. Run them in dev and qa and staging so you know they work. Then you go to prod and are done.

The less manual steps the less mistakes will happen.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: