【问题标题】:HowTO: Import PSQL dump file ? pgAdminConsole or PSQL console如何:导入 MYSQL 转储文件? pgAdmin 控制台或 PSQL 控制台
【发布时间】:2014-04-04 22:06:50
【问题描述】:

大家好,正如标题所说,我在尝试从转储文件导入“创建”新数据库时遇到问题。当我尝试运行 sql 查询时 - 我收到有关

的错误

'复制'

。当你通过 psql 控制台运行时,我得到了

错误的命令\n

SQL 文件看起来像这样(只是一个示例 ofc,因为整个文件都很大..)

--
-- PostgreSQL database dump
--

-- Dumped from database version 9.1.12
-- Dumped by pg_dump version 9.3.3
-- Started on 2014-04-01 17:05:29

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 209 (class 1259 OID 32258844)
-- Name: stats_call; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE bensonsorderlystats_call (
    id integer,
    callerid text,
    entry timestamp with time zone,
    oqid integer,
    oqnumcalls integer,
    oqannounced double precision,
    oqentrypos integer,
    oqexitpos integer,
    oqholdtime double precision,
    acdcallid text,
    acdentry timestamp with time zone,
    acdqueueid integer,
    acdagents integer,
    acdentrypos integer,
    acdexitpos integer,
    acdholdtime double precision,
    holdtime double precision,
    exit timestamp with time zone,
    agentid integer,
    talktime double precision,
    calltime double precision,
    callend timestamp with time zone,
    reason integer,
    wraptime double precision,
    acdsubqueueid integer,
    working integer,
    calledback integer,
    accountid integer,
    needed integer,
    ringingagentid integer,
    ringtime double precision,
    presented integer,
    notecode integer,
    note text,
    recording text,
    wrapcode integer
);


ALTER TABLE public.stats_call OWNER TO postgres;

--
-- TOC entry 2027 (class 0 OID 32258844)
-- Dependencies: 209
-- Data for Name: stats_call; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY stats (id, callerid, entry, oqid, oqnumcalls, oqannounced, oqentrypos, oqexitpos, oqholdtime, acdcallid, acdentry, acdqueueid, acdagents, acdentrypos, acdexitpos, acdholdtime, holdtime, exit, agentid, talktime, calltime, callend, reason, wraptime, acdsubqueueid, working, calledback, accountid, needed, ringingagentid, ringtime, presented, notecode, note, recording, wrapcode) FROM stdin;
1618693 unknown 2014-02-01 02:59:48.297+00  2512    \n  \n  \n  \n  0   1391223590.58579    2014-02-01 02:59:48.297+00  1872    \n

当我运行导入时在上面的屏幕上 \i C:<path>/file.sql with delimiter \n 我得到错误的命令\n 我也试过了

`\i C:<path>/file.sql delimiter \n`
`\i C:<path>/file.sql`

谁能告诉我,如何将此数据库放入服务器。帮助表示赞赏。谢谢

【问题讨论】:

    标签: sql postgresql psql pgadmin


    【解决方案1】:

    一般情况下,您可以在包含 SQL 文件之前在psql 中发出\set ON_ERROR_STOP,以在第一个错误处停止并且不会被后续错误淹没。

    当试图复制到一个不存在的表中时,COPY 失败并且它之后的所有数据都被拒绝并出现很多错误消息。

    看看你转储的开头,似乎确实有一些问题。

    它创建一个名为 bensonsorderlystats_call 的表,然后将 postgres 的所有权授予另一个不应该存在的 public.stats_call

    然后它会尝试将数据复制到一个名为 stats 的表中,假设您要恢复到一个空数据库中,该表也从未创建过。

    看起来好像有人手动编辑了转储并搞砸了。

    【讨论】:

    • 好的,所以我手动更正了这些错误 - 创建了一个与转储文件同名的表,但我仍然在复制时收到这些错误。它抱怨无效字符/未知命令\n
    • @MaciejCygan:这是第一条重要的错误消息。
    【解决方案2】:

    试试psql -U username -f dump.sql database_name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-30
      • 2020-04-10
      • 2020-07-16
      • 2021-06-05
      • 2012-02-28
      相关资源
      最近更新 更多