บทความ

กำลังแสดงโพสต์จาก ตุลาคม, 2019

เมื่อทำการ Restore database ของ Postgresql แล้วแต่ว่า index sequences ทุกตารางผิด

เหตุการณ์ เมื่อทำการ restore database ด้วย pg_restore แล้ว Index sequences ของทุกตารางนั้นเริ่มนับ 1 ใหม่หมด ทำให้การบันทึกข้อมูลหลังจาก restore เรียบแล้วจะเกิด error duplicate key id สาเหตุ ไม่ทราบ วิธีการแก้ไข เมื่อ restore เรียบร้อยแล้วเราจะต้องทำการใส่คำสั่งต่อไปนี้ เพื่อทำการ reindex ใหม่ SELECT pg_catalog . setval ( pg_get_serial_sequence ( 'table_name' , 'id' ), ( SELECT MAX ( id ) FROM table_name ) +1 );