问题
Trying to dump a partitioned table from one server to another in PostgreSQL (9.4.5). Fairly new to postgres, and inherited the project, please let me know if more background info is needed.
dbname=> SELECT COUNT (id) FROM parent_table_to_copy;
count
--------
499992
(1 row)
parent_table_to_copy has a trigger:
parent_table_to_copy_trigger BEFORE INSERT ON parent_table_to_copy FOR EACH ROW EXECUTE PROCEDURE parent_table_to_copy_function()
Maybe not important, but the function is a series of ELSIF's that partition parent_table_to_copy into 26 children alphabetically by the first letter for the record for the name column. For example if I wanted all the records whose name starts with "A" from parent_table_to_copy, a subset is returned with:
dbname=> SELECT COUNT(id) FROM child_table_a;
count
-------
34064
(1 row)
Now for the dump/restore into our backup of the database housed on hostname2
I used --inserts because of the insert trigger described above, didn't think the defaultCOPY statement would work.
pg_dump --host=hostname1 --username=user --table="parent_table_to_copy" --inserts --data-only --file=dump_out.sql dbname
Contents of dump_out.sql However there doesn't seem to be any INSERT commands. If I take out --inserts then a COPY command appears.
--
-- PostgreSQL database dump
--
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;
--
-- Data for Name: parent_table_to_copy; Type: TABLE DATA; Schema: public; Owner: user
--
--
-- PostgreSQL database dump complete
--
Finally, psql -U user -h hostname2 -d dbname -f dump_out.sql just returns seven SET commands and when I SELECT from hostname2 there are 0 records.
Any insight would be greatly appreciated, thank you for reading. -Kevin
Edit Below ~ Create table statement included
CREATE TABLE IF NOT EXISTS parent_table_to_copy
(
id INTEGER NOT NULL,
name CHARACTER VARYING(25) NOT NULL,
vartype CHARACTER VARYING(26) NOT NULL,
var2type NUMERIC NOT NULL
);
CREATE TABLE child_table_a
( CONSTRAINT child_table_a_id_fk FOREIGN KEY (id) REFERENCES some_table (id) MATCH FULL ON DELETE CASCADE,
CONSTRAINT child_table_a_gene_name_fk FOREIGN KEY (name) REFERENCES some_other_table (name) MATCH FULL ON DELETE CASCADE,
CHECK (name like 'A%')
) INHERITS (parent_table_to_copy);
CREATE INDEX child_type_a ON child_table_a (id,name,vartype);
来源:https://stackoverflow.com/questions/34496006/postgresql-dump-and-restore-partitioned-table-w-insert-trigger-from-one-serve