Postgres latest sequence id and uncommitted writes
select max(id) is the most reliable way.
It's also quite fast if you have a b-tree index on id (performance is virtually independent of the size of the table).