Not sure how it is out of sync. How can I fix this permanently. I ran vacuum analyze verbose; still same error
Vacuuming the table doesn't change the fact that your sequence isn't generating unique keys. Without knowing the full history of the table, I can only speculate as to how keys got inserted that are beyond the sequence's current vlue, but most likely you will need to use the sequence manipulation function setval to set the sequence to at least one greater than the current maximum value.