PostgreSQL: Transactions, Row Locks, and Advisory Locks

How PostgreSQL row locks (for update, for share) and advisory locks interact: session vs transaction scope, deadlocks, bigint keys, and fetch-lock-refetch.