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.