web-dev-qa-db-fra.com

Erreur lors de la création de SEQUENCES lors de la restauration de la base de données PostgreSQL

serX a les subventions suivantes:

CREATE ROLE "UserX" LOGIN PASSWORD 'pass';
CREATE DATABASE "DBX" WITH OWNER="UserX" ENCODING='UTF8' TABLESPACE=pg_default CONNECTION LIMIT=-1;
GRANT CONNECT ON DATABASE "DBX" TO "UserX";
GRANT USAGE ON SCHEMA public TO "UserX";
GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA public TO "UserX";
ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO "UserX";
ALTER DEFAULT PRIVILEGES GRANT ALL ON SEQUENCES TO "UserX";

J'obtiens les erreurs suivantes en essayant de restaurer son vidage sur une autre base de données:

pg_restore: creating SEQUENCE "public.tblX_Id_seq"
pg_restore: [archiver (db)] Error from TOC entry 218; 1259 438745 SEQUENCE tblX_Id_seq UserX
pg_restore: [archiver (db)] could not execute query: ERROR:  syntax error at or near "AS"
LINE 2:     AS integer
            ^
    Command was: CREATE SEQUENCE "tblX_Id_seq"
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACH...
pg_restore: [archiver (db)] could not execute query: ERROR:  relation "tblX_Id_seq" does not exist
    Command was: ALTER TABLE "tblX_Id_seq" OWNER TO "UserX";


pg_restore: creating SEQUENCE OWNED BY "public.tblX_Id_seq"
pg_restore: [archiver (db)] Error from TOC entry 3569; 0 0 SEQUENCE OWNED BY tblX_Id_seq UserX
pg_restore: [archiver (db)] could not execute query: ERROR:  relation "tblX_Id_seq" does not exist
    Command was: ALTER SEQUENCE "tblX_Id_seq" OWNED BY "tblX"."Id";

...

pg_restore: creating DEFAULT "public.tblX Id"
pg_restore: [archiver (db)] Error from TOC entry 2995; 2604 438750 DEFAULT tblX Id UserX
pg_restore: [archiver (db)] could not execute query: ERROR:  relation "tblX_Id_seq" does not exist
    Command was: ALTER TABLE ONLY "tblX" ALTER COLUMN "Id" SET DEFAULT nextval('"tblX_Id_seq"'::regclass);

...

pg_restore: executing SEQUENCE SET tblX_Id_seq
pg_restore: [archiver (db)] Error from TOC entry 3607; 0 0 SEQUENCE SET tblX_Id_seq UserX
pg_restore: [archiver (db)] could not execute query: ERROR:  relation "tblX_Id_seq" does not exist
LINE 1: SELECT pg_catalog.setval('"tblX_Id_seq"', 1573, true);
                                 ^
    Command was: SELECT pg_catalog.setval('"tblX_Id_seq"', 1573, true);

Une suggestion sur ce que je fais mal?

11
Babak

Vous essayez de restaurer un vidage à partir d'une base de données v10 dans une ancienne version de PostgreSQL (CREATE SEQUENCE ... AS est nouveau dans la v10).

Cela n'est pas pris en charge et ne fonctionnera pas. Vous pouvez créer un script SQL avec pg_restore et modifiez-le manuellement. Ou mettez à niveau la base de données de destination.

20
Laurenz Albe

J'ai pris ces notes:

PRISE EN CHARGE DE TOUTES LES BASES DE DONNÉES COMPRIMÉES

pg_dump -U {usuario} -h {hôte} -W {base de données} | gzip -c> archivo.gz

RESTAURER À PARTIR DE BACK GZIP

gunzip -c {archivo.gz} | psql -h {Host} -U postgres {base de données}

RESTAURER DE LA SAUVEGARDE GZIP DE v10 à v9.x

gunzip -c {archivo.gz} | sed -e '/ AS entier/d' | psql -U postgres -h {hôte} -W {base de données}

5
Francisco