Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying PostgreSQL 9 Administration Cookbook - Second Edition
  • Table Of Contents Toc
PostgreSQL 9 Administration Cookbook - Second Edition

PostgreSQL 9 Administration Cookbook - Second Edition

By : Simon Riggs, GIANNI CIOLLI, Hannu Krosing, Gabriele Bartolini
5 (3)
close
close
PostgreSQL 9 Administration Cookbook - Second Edition

PostgreSQL 9 Administration Cookbook - Second Edition

5 (3)
By: Simon Riggs, GIANNI CIOLLI, Hannu Krosing, Gabriele Bartolini

Overview of this book

Through example-driven recipes, with plenty of code, focused on the most vital features of the latest PostgreSQL version (9.4), both administrators and developers will follow short, specific guides to understand and leverage useful Postgre functionalities to create better and more efficient databases.
Table of Contents (14 chapters)
close
close
13
Index

Using optimistic locking

Suppose you are doing lots of transactions, like the following:

BEGIN;
SELECT * FROM accounts WHERE holder_name ='BOB' FOR UPDATE;
<do some calculations here>
UPDATE accounts SET balance = 42.00 WHERE holder_name ='BOB';
COMMIT;

Then, you may gain some performance by moving from explicit locking (SELECT … FOR UPDATE) to optimistic locking.

Optimistic locking assumes that others don't update the same record, and checks this at update time instead of locking the record for the time it takes to process the information on the client side.

How to do it…

Rewrite your application so that the preceding transaction is transformed into something like the following (pay attention to the placeholders):

BEGIN;
SELECT A.*, (A.*::text) AS old_acc_info
  FROM accounts a WHERE holder_name ='BOB';
<do some calculations here>
UPDATE accounts SET balance = 42.00
 WHERE holder_name ='BOB'
 AND (A.*::text) = <old_acc_info...
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
PostgreSQL 9 Administration Cookbook - Second Edition
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon