# PostgreSQL Datenbankstruktur exportieren und importieren



## Shaddow (29. Mai 2009)

Hi ich hab mal wieder eine Frage 

Ich habe meine DB auf postgreSQL basierend und will die nun mal woanders importieren. Ich exportiere sie also und bekomme einen Code ala:

```
--
-- PostgreSQL database dump
--

SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: admin
--

CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO admin;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: article; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "article" (
    "ID" integer NOT NULL,
    amount integer,
    description text,
    price real
);


ALTER TABLE public."article" OWNER TO admin;

--
-- Name: article_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "article_ID_seq"
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."article_ID_seq" OWNER TO admin;

--
-- Name: article_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "article_ID_seq" OWNED BY "article"."ID";


--
-- Name: article_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"article_ID_seq"', 16, true);


--
-- Name: article_bill_mn; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "article_bill_mn" (
    "billID" integer,
    "articleID" integer,
    amount integer
);


ALTER TABLE public."article_bill_mn" OWNER TO admin;

--
-- Name: article_offer_mn; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "article_offer_mn" (
    "articleID" integer,
    "offerID" integer,
    amount integer,
    "ID" integer NOT NULL
);


ALTER TABLE public."article_offer_mn" OWNER TO admin;

--
-- Name: article_offer_mn_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "article_offer_mn_ID_seq"
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."article_offer_mn_ID_seq" OWNER TO admin;

--
-- Name: article_offer_mn_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "article_offer_mn_ID_seq" OWNED BY "article_offer_mn"."ID";


--
-- Name: article_offer_mn_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"article_offer_mn_ID_seq"', 14, true);


--
-- Name: bill; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "bill" (
    "ID" integer NOT NULL,
    "customerID" integer,
    "offerID" integer,
    date date,
    "contractDate" date,
    "letterHead" text,
    "letterBody" text,
    "billCombo" integer,
    price real
);


ALTER TABLE public."bill" OWNER TO admin;

--
-- Name: bill_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "bill_ID_seq"
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."bill_ID_seq" OWNER TO admin;

--
-- Name: bill_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "bill_ID_seq" OWNED BY "bill"."ID";


--
-- Name: bill_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"bill_ID_seq"', 1, false);


--
-- Name: coupon; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "coupon" (
    "ID" integer NOT NULL,
    "customerID" integer,
    description text,
    "dueDate" date,
    honoured date
);


ALTER TABLE public."coupon" OWNER TO admin;

--
-- Name: coupon_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "coupon_ID_seq"
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."coupon_ID_seq" OWNER TO admin;

--
-- Name: coupon_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "coupon_ID_seq" OWNED BY "coupon"."ID";


--
-- Name: coupon_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"coupon_ID_seq"', 1, false);


--
-- Name: customer; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "customer" (
    "ID" integer NOT NULL,
    company character varying(255),
    gender character varying(255),
    "firstName" character varying(255),
    "lastName" character varying(255),
    street character varying(255),
    number character varying(255),
    "postCode" integer,
    city character varying(255),
    "telefoneNumber" character varying(255),
    telefax character varying(255),
    "cellPhone" character varying(255),
    "taxNr" character varying(255),
    "USTIDNr" character varying(255),
    email character varying(255),
    website character varying(255),
    "customerSince" date,
    "customerUntil" date
);


ALTER TABLE public."customer" OWNER TO admin;

--
-- Name: customer_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "customer_ID_seq"
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."customer_ID_seq" OWNER TO admin;

--
-- Name: customer_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "customer_ID_seq" OWNED BY "customer"."ID";


--
-- Name: customer_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"customer_ID_seq"', 9, true);


--
-- Name: offer; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "offer" (
    "ID" integer NOT NULL,
    "customerID" integer NOT NULL,
    date date,
    "letterHead" text,
    "letterBody" text,
    price double precision
);


ALTER TABLE public."offer" OWNER TO admin;

--
-- Name: offer_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "offer_ID_seq"
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."offer_ID_seq" OWNER TO admin;

--
-- Name: offer_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "offer_ID_seq" OWNED BY "offer"."ID";


--
-- Name: offer_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"offer_ID_seq"', 47, true);


--
-- Name: products; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE "products" (
    "ID" integer NOT NULL,
    description text,
    "purchasePrice" real,
    "invoicePrice" real
);


ALTER TABLE public."products" OWNER TO admin;

--
-- Name: produkte_ID_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE "produkte_ID_seq"
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public."produkte_ID_seq" OWNER TO admin;

--
-- Name: produkte_ID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE "produkte_ID_seq" OWNED BY "products"."ID";


--
-- Name: produkte_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: admin
--

SELECT pg_catalog.setval('"produkte_ID_seq"', 1, false);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "article" ALTER COLUMN "ID" SET DEFAULT nextval('"article_ID_seq"'::regclass);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "article_offer_mn" ALTER COLUMN "ID" SET DEFAULT nextval('"article_offer_mn_ID_seq"'::regclass);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "bill" ALTER COLUMN "ID" SET DEFAULT nextval('"bill_ID_seq"'::regclass);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "coupon" ALTER COLUMN "ID" SET DEFAULT nextval('"coupon_ID_seq"'::regclass);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "customer" ALTER COLUMN "ID" SET DEFAULT nextval('"customer_ID_seq"'::regclass);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "offer" ALTER COLUMN "ID" SET DEFAULT nextval('"offer_ID_seq"'::regclass);


--
-- Name: ID; Type: DEFAULT; Schema: public; Owner: admin
--

ALTER TABLE "products" ALTER COLUMN "ID" SET DEFAULT nextval('"produkte_ID_seq"'::regclass);


--
-- Data for Name: article; Type: TABLE DATA; Schema: public; Owner: admin
--

INSERT INTO "article" VALUES (1, 1, 'test', 0.5);
INSERT INTO "article" VALUES (2, 1, 'test', 0.5);
INSERT INTO "article" VALUES (3, 123, 'Bezeichnungeewffe', 0.5);
INSERT INTO "article" VALUES (4, 0, 'Bezeichnung', 0);
INSERT INTO "article" VALUES (5, 1, 'Bezeichnung', 12);
INSERT INTO "article" VALUES (6, 6, 'Bezeichnung', 0.5);
INSERT INTO "article" VALUES (7, 7, 'Bezeichnung', 100);
INSERT INTO "article" VALUES (8, 72, 'Bezeichnung', 100);
INSERT INTO "article" VALUES (9, 9, 'Bezeichnung111', 1);
INSERT INTO "article" VALUES (10, 10, 'Bezeichnung111111111111', 12333);
INSERT INTO "article" VALUES (11, 11, ' ngfngfngfgfnfn', 3445);
INSERT INTO "article" VALUES (12, 11, ' ngfngfngfgfnfn', 3445);
INSERT INTO "article" VALUES (13, 11, ' ngfngfngfgfnfn', 3445);
INSERT INTO "article" VALUES (14, 11, ' ngfngfngfgfnfn', 3445);
INSERT INTO "article" VALUES (15, 455, ' ngfngfngfgfnfn', 3445);


--
-- Data for Name: article_bill_mn; Type: TABLE DATA; Schema: public; Owner: admin
--



--
-- Data for Name: article_offer_mn; Type: TABLE DATA; Schema: public; Owner: admin
--

INSERT INTO "article_offer_mn" VALUES (1, 47, 1, 11);
INSERT INTO "article_offer_mn" VALUES (7, 47, 12, 13);
INSERT INTO "article_offer_mn" VALUES (4, 47, 3, 14);


--
-- Data for Name: bill; Type: TABLE DATA; Schema: public; Owner: admin
--



--
-- Data for Name: coupon; Type: TABLE DATA; Schema: public; Owner: admin
--



--
-- Data for Name: customer; Type: TABLE DATA; Schema: public; Owner: admin
--

INSERT INTO "customer" VALUES (6, 'Testfirma', 'MÃ¤nnlich', 'Maxwwqdwqd', 'Mustermann111', 'TeststraÃŸe', 'TestHausnummer', 99999, 'Teststadt', '0001', '0002', '0003', '0004', '0005', 'testmail', 'testwebsite', '2009-01-01', '2009-01-02');
INSERT INTO "customer" VALUES (7, 'fwwf', 'weiblich', 'martina', 'fewff', 'fewwfwfwef', 'ewfewf', 234324324, 'ewfwfwf', 'we', 'wef', 'ewfewfe', 'fewf', 'ffwef', 'ewfwf', 'wefef', '2009-09-09', '2009-09-09');
INSERT INTO "customer" VALUES (8, '43t44t43', 'mÃ¤nnlich', 'Patrick', 'blubb', 'ewfewf', 'ewef', 2123, 'ewfdew', 'ewfewf', 'ewf', 'fewf', 'efewfewf', 'ewffew', 'fewfewf', 'ewff', '2001-01-01', '2001-01-01');
INSERT INTO "customer" VALUES (9, 'efdewfe', 'weiblich', 'Freddy', 'blaa', 'fewef', 'wefewf', 222, 'ewfew', 'fewfew', 'fewfewfe', 'fefewf', 'fwef', 'ewfewf', 'efewf', 'ewfew', '2001-01-01', '2001-01-01');


--
-- Data for Name: offer; Type: TABLE DATA; Schema: public; Owner: admin
--

INSERT INTO "offer" VALUES (47, 7, '2009-01-01', 'efefffewewfewfewf', 'ewfewfewf', 111);


--
-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: admin
--



--
-- Name: article_offer_mn_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "article_offer_mn"
    ADD CONSTRAINT "article_offer_mn_pkey" PRIMARY KEY ("ID");


--
-- Name: article_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "article"
    ADD CONSTRAINT "article_pkey" PRIMARY KEY ("ID");


--
-- Name: bill_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "bill"
    ADD CONSTRAINT "bill_pkey" PRIMARY KEY ("ID");


--
-- Name: coupon_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "coupon"
    ADD CONSTRAINT "coupon_pkey" PRIMARY KEY ("ID");


--
-- Name: customer_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "customer"
    ADD CONSTRAINT "customer_pkey" PRIMARY KEY ("ID");


--
-- Name: offer_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "offer"
    ADD CONSTRAINT "offer_pkey" PRIMARY KEY ("ID");


--
-- Name: produkte_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "products"
    ADD CONSTRAINT "produkte_pkey" PRIMARY KEY ("ID");


--
-- Name: public; Type: ACL; Schema: -; Owner: admin
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM admin;
GRANT ALL ON SCHEMA public TO admin;
GRANT ALL ON SCHEMA public TO PUBLIC;


--
-- PostgreSQL database dump complete
--
```

Genauso exportiert mir das phpPGAdmin
Wenn ich nun eine andere Datenbank erzeuge und genau diesen Code importiere, kommen Fehler.. Und nicht wenige. Das ansich verstehe ich schon nicht. Was mir postgresql exportiert, müsste ich doch direkt wieder importieren können...

Zuerst kommen Fehler ala 


> ERROR:  language "plpgsql" already exists


Wenn ich die entsprechende Zeile lösche, geht es weiter mit Fehlern die an dem Einfügen der Daten in die Tabellen meckern.. erst wenn die plpgsql raus ist und alle Daten, sodass wirklich nur noch die Struktur übrig bleibt, kann das Script ausgeführt werden.

Woran kann das liegen? Ich würd eigentlich schon gern mal die ganzen Daten mit übernehmen wollen ^^

Danke schonmal


----------



## musiKk (30. Mai 2009)

Shaddow hat gesagt.:


> geht es weiter mit Fehlern die an dem Einfügen der Daten in die Tabellen meckern..



Die da lauten?


----------



## Shaddow (30. Mai 2009)

Okay der Fehler beim Insert war wohl von mir, weil ich beim Exportieren Copy und nicht SQL ausgewählt hatte.
Dennoch kommt immer dieser erste Fehler, der behoben wird, wenn ich 

```
CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO admin;
```
rauslösche


----------

