Brian Mehrman

Postgresql Record Locking

ruby postgresql

Database Lock Modes

Postgresql provides different locking modes to control concurrency within the database. Locks are automatically acquired by most Postgres commands to make sure tables are not dropped or modified while a command is executed. Locks can also be acquired manually for application level control.

ActiveRecord provides the interface between the Rails application and the database. Using ActiveRecord we can create these database level locks.

Optimistic vs Pessimistic Locking

ruby rails postgres

Data integrity is at risk once two sessions begin to work on the same records… - Martin Fowler

Optimistic Locking

Is a data access strategy where it is assumed that the chance of conflict between sessions is very low. Changes from one session are validated before being committed to the database.

Pessimistic Locking

This an opposing data access strategy assumes that conflicts between sessions is highly likely. Conflicts are prevented by forcing all transactions to obtain a lock on the data (record or table) before it can start to use it.

Git Tips



Git is a free version control system designed for both small and large projects.

Class_eval vs Define_method

ruby meta programming

Meta Programming

Having to write redundant methods can lead to hundreds of lines of code that can be hard to maintain. Meta programming provides us with tools that allow us to write code that writes its self.