简体   繁体   English

如何:导入PSQL转储文件? pgAdminConsole或PSQL控制台

[英]HowTO: Import PSQL dump file ? pgAdminConsole or PSQL console

Hello guys as the title says I am having trouble trying to import ' create ' new database from dump file. 大家好,标题说我在尝试从转储文件导入'create'新数据库时遇到麻烦。 When i try to run sql query - i get error regarding 当我尝试运行sql查询时-我收到有关以下内容的错误

' COPY ' '复制'

. When u run through psql console i get 当您通过psql控制台运行时,我得到

wrong command \\n 错误的命令\\ n

the SQL file looks like this ( just a sample ofc as the whole lot is quite big .. ) 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

在此处输入图片说明

on the above screen when i run the import with \\i C:<path>/file.sql with delimiter \\n i get wrong command \\ni have tried also 在上面的屏幕上,当我使用\\i C:<path>/file.sql with delimiter \\n运行导入时,我得到了错误的命令\\ ni也尝试过

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

Can any one tell me please, how to get this db into server. 谁能告诉我,如何将此数据库放入服务器。 Help appreciated. 帮助表示赞赏。 Thanks 谢谢

In general, you can issue \\set ON_ERROR_STOP in psql before including a SQL file, to stop at the first error and not be flooded by subsequent errors. 通常,可以在包含SQL文件之前在psql发出\\set ON_ERROR_STOP ,以在第一个错误处停止并且不会被后续错误淹没。

When trying to copy into a non-existing table, COPY fails and all the data after it is rejected with a lot error messages. 尝试复制到不存在的表时, COPY失败,并且所有数据被拒绝后,出现很多错误消息。

Looking at the beginning of your dump, there seems to be a few problems indeed. 从转储的开始看,确实确实存在一些问题。

It creates a table named bensonsorderlystats_call but then gives ownership to postgres to another public.stats_call which is not supposed to exist. 它创建一个名为bensonsorderlystats_call的表,但随后将postgres的所有权授予另一个public.stats_call存在的public.stats_call

And then it tries to COPY data into a table named stats which is also never created, assuming you're restoring into an empty database. 然后,它会尝试将数据复制到一个名为stats的表中,假设您要还原到一个空数据库中,该表也永远不会创建。

It looks as if someone manually edited the dump and messed up. 好像有人手动编辑了转储并将其弄乱了。

尝试使用psql -U username -f dump.sql database_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM