Error in creating SEQUENCEs when restoring the PostgreSQL database

I got the solution to restore the database from higher version to a lower version. if sequence error occurs during restore the database just remove As integer from dump.sql file and restore it will solve the sequence error.

For Example:

 CREATE SEQUENCE "tblX_Id_seq"
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACH...

Remove AS integer

CREATE SEQUENCE "tblX_Id_seq"
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACH...

You are trying to restore a dump from a v10 database into an older version of PostgreSQL (CREATE SEQUENCE ... AS is new in v10).

That is not supported and won't work. You can create an SQL script with pg_restore and edit it manually. Or upgrade the destination database.


I have taken these notes:

SUPPORT ALL COMPRESSED DATABASE

pg_dump -U {usuario} -h {host} -W {database} | gzip -c > archivo.gz

RESTORE FROM BACK GZIP

gunzip -c {archivo.gz} | psql -h {host} -U postgres {database}

RESTORE FROM GZIP BACKUP FROM v10 to v9.x

gunzip -c {archivo.gz} | sed -e '/AS integer/d' | psql -U postgres -h {host} -W {database}