一些序列不在pg_dump的转储中

时间:2013-06-20 12:59:55

标签: postgresql sequence pgadmin pg-dump

我想pg_dump我的数据库,并且存在一些问题,即在转储文件中生成了一些序列,而有些序列则没有。

使用表infrastruktur_pictures,它与表hoehenprofile一起使用它不起作用。以下是关于pgadmin3表格的信息:

hoehenprofile

CREATE SEQUENCE "hoehenprofile_HID_seq"
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 14289
  CACHE 1;
ALTER TABLE "hoehenprofile_HID_seq";

CREATE TABLE hoehenprofile
(
  "HID" serial NOT NULL,
  hoehenprofil character varying(255),
  CONSTRAINT "HID" PRIMARY KEY ("HID")
)
WITH (
  OIDS=FALSE
);
ALTER TABLE hoehenprofile ADD COLUMN "HID" integer;
ALTER TABLE hoehenprofile ALTER COLUMN "HID" SET NOT NULL;
ALTER TABLE hoehenprofile ALTER COLUMN "HID" SET DEFAULT nextval('"hoehenprofile_HID_seq"'::regclass);

infrastruktur_pictures

CREATE SEQUENCE "infrastruktur_pictures_IPID_seq"
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
ALTER TABLE "infrastruktur_pictures_IPID_seq";

CREATE TABLE infrastruktur_pictures
(
  "IPID" serial NOT NULL,
  picture character varying(255) NOT NULL,
  picture_text text,
  fotograf text,
  CONSTRAINT prim PRIMARY KEY ("IPID")
)
WITH (
  OIDS=FALSE
);
ALTER TABLE infrastruktur_pictures ADD COLUMN "IPID" integer;
ALTER TABLE infrastruktur_pictures ALTER COLUMN "IPID" SET NOT NULL;
ALTER TABLE infrastruktur_pictures ALTER COLUMN "IPID" SET DEFAULT nextval('"infrastruktur_pictures_IPID_seq"'::regclass);

在转储文件中,生成的hoehenprofile代码如下所示(没有生成序列):

--
-- TOC entry 145 (class 1259 OID 67719)
-- Name: hoehenprofile; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE hoehenprofile (
    "HID" integer DEFAULT nextval('"hoehenprofile_HID_seq"'::regclass) NOT NULL,
    hoehenprofil character varying(255)
);

infrastruktur_pictures的代码如下所示:

-
-- TOC entry 152 (class 1259 OID 67750)
-- Name: infrastruktur_pictures; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE infrastruktur_pictures (
    "IPID" integer NOT NULL,
    picture character varying(255) NOT NULL,
    picture_text text,
    fotograf text
);


--
-- TOC entry 4230 (class 0 OID 0)
-- Dependencies: 152
-- Name: TABLE infrastruktur_pictures; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON TABLE infrastruktur_pictures IS 'Bilder im Infrastruktur Bereich des Backends';


--
-- TOC entry 153 (class 1259 OID 67756)
-- Name: infrastruktur_pictures_IPID_seq; Type: SEQUENCE; Schema: public; Owner: -
--

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


--
-- TOC entry 4231 (class 0 OID 0)
-- Dependencies: 153
-- Name: infrastruktur_pictures_IPID_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE "infrastruktur_pictures_IPID_seq" OWNED BY infrastruktur_pictures."IPID";

我可以在pgadmin3中看到这两个表之间的唯一区别。当我在对象浏览器中单击特定的cloumn(HID,IPID)并查看其右侧的属性选项卡时,我可以看到在HID列中未设置序列属性。

1 个答案:

答案 0 :(得分:1)

不同之处在于,在第二种情况下,序列由表所有。检查pg_dump的最后一行。

这是因为,当您使用serial pseudo-datatype创建表时,会自动添加所有权。但是当您手动创建序列时,您没有设置“OWNED BY”。