Postgresql, running sql and get error: COPY from stdin failed

Postgresql, running sql and get error: COPY from stdin failed

Postgresql 12 使用 pgAdmin4,菜单 Tools/Backup/Format-Plain 将数据库备份到 sql 文件,如下所示:

--
-- PostgreSQL database dump
--
-- Dumped from database version 12.3
-- Dumped by pg_dump version 12.3
-- Started on 2020-08-06 17:38:54
SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- TOC entry 202 (class 1259 OID 17973)
-- Name: customers; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.customers (
    "CustomerID" character varying(32) NOT NULL,
    "Name" character varying(128),
    "AddressLine" character varying(128)
);
ALTER TABLE public.customers OWNER TO postgres;
--
-- TOC entry 3232 (class 0 OID 17973)
-- Dependencies: 202
-- Data for Name: customers; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY public.customers ("CustomerID", "Name", "AddressLine") FROM stdin;
\.
-- Completed on 2020-08-06 17:38:54
--
-- PostgreSQL database dump complete
--

创建一个新的空数据库并尝试 运行 在 sql 文件上方创建模式和数据。 “COPY”下的反斜杠出现错误: pgAdmin 出现错误:

ERROR:  syntax error at or near "\"
LINE 45: \.
         ^
SQL state: 42601
Character: 1092

我怎样才能正确地运行 sql 文件来恢复架构和数据?

您必须使用 psql 恢复纯格式 pg_dump。 pgAdmin 或其他客户端 juat 不会做,除非你使用 pg_dump--inserts 选项。

原因是其他客户端无法处理单个输入文件中 SQL 语句和 COPY 数据的混合。