Postgresql reset sequence

postgresql
SELECT setval('your_table_id_seq', COALESCE((SELECT MAX(id)+1 FROM your_table), 1), false)

or 

SELECT
	setval(pg_get_serial_sequence('tbl', 'id'), COALESCE(max(id) + 1, 1), FALSE)
FROM
	tbl;