code: protected function acquireLock($name, $timeout = 0)
      {
          list($key1, $key2) = $this->getKeysFromName($name);
  
          return $this->retryAcquire($timeout, function () use ($key1, $key2) {
              return $this->db->useMaster(function ($db) use ($key1, $key2) {
                  /** @var \yii\db\Connection $db */
                  return (bool) $db->createCommand(
                      'SELECT pg_try_advisory_lock(:key1, :key2)',
                      [':key1' => $key1, ':key2' => $key2]
                  )->queryScalar();
              });
          });
      }
docs: Acquires lock by given name.
  @param string $name of the lock to be acquired.
  @param int $timeout time (in seconds) to wait for lock to become released.
  @return bool acquiring result.
  @see http://www.postgresql.org/docs/9.0/static/functions-admin.html