Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSql : ERROR: relation "sequence" does not exist while restoring from dump file

I get the following error while restoring database from dump file on server:

ERROR: relation "table_id_seq" does not exist
LINE 1: SELECT pg_catalog.setval('table_id_seq', 362, true);

  • my local psql version is 10.2
  • server psql version is 9.6.8

Here is my dump command:

pg_dump -U username -h localhost db_name > filename.sql

Here is my restore command on server:

psql -U username -h localhost db_name < filename.sql

Please help, Thanks.

like image 856
Saly Avatar asked Mar 19 '18 04:03

Saly


1 Answers

After I got information from @clemens and make some research I found that, in my dump file on section CREATE SEQUENCE table_id_seq has a statement AS integer that why when I restored into new database it did not create the nextval() for the sequence. If I remove the statement AS integer from the CREATE SEQUENCE section it works find.

In my dump file:

CREATE SEQUENCE table_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

Remove AS integer from dump file

CREATE SEQUENCE table_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;
like image 178
Saly Avatar answered Oct 13 '22 20:10

Saly