什么是避免共享锁和独占锁的合适方法?

I have sufficiently highload system built with PostgreSql 9.1 and PHP 5.3.

I have to store last login time and ip user each time after user login. When user logins system stores it to Redis and I have script in crontab which executes each minute and fetches data from Redis and updates user's rows with last login time and ip in DB with one big query.

If at this moment some scripts starts to execute update query of user table I could find shared locks errors in PostgreSql log. Huge problem that php scripts fall down when this error happens in PostgreSql without any exception from PDO.

I know to avoid shared locks I need to execute update query one after the other, not concurrently. But to implement it isn't so easy in my system. What is the best approach to avoid shared locks?