一、pg_dump
| 序号 | 选项 | 说明 |
|---|---|---|
| 1 | –on-conflict-do-nothing | 此选项自动将ON CONFLICT DO NOTHING子句分配给输出INSERT语句。必须在使用–inserts选项或–column-inserts选项指定。 |
| 2 | –extra-float-digits | 如果为此参数指定了整数值,则在使用pg_dump命令获取数据之前执行“ SET extra_float_digits =指定值”语句。转储文件不包含SET语句。可以指定的值的范围是-15至3。如果指定了非数字值,则将其视为0。 |
| 3 | –rows-per-insert | This option is used with the --inserts option. Multiple tuples can be inserted in a single INSERT statement. The range of values is 1 to 2,147,483,647. |
[postgres@host1 ~]$ pg_dump -t test --inserts --on-conflict-do-nothing
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.4
-- Dumped by pg_dump version 12.4
......
--
-- Name: test; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.test (
id integer NOT NULL,
name text
);
ALTER TABLE public.test OWNER TO postgres;
--
-- Data for Name: test; Type: TABLE DATA; Schema: public; Owner: postgres
--
INSERT INTO public.test VALUES (1, 'Li Ming') ON CONFLICT DO NOTHING;
INSERT INTO public.test VALUES (2, 'Han Meimei') ON CONFLICT DO NOTHING;
INSERT INTO public.test VALUES (3, 'Zhang Qiang') ON CONFLICT DO NOTHING;
--
-- Name: test test_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.test
ADD CONSTRAINT test_pkey PRIMARY KEY (id);
--
-- PostgreSQL database dump complete
--
[postgres@host1 ~]$ pg_dump -t test2 --inserts --rows-per-insert=2
--
-- PostgreSQL database dump
--
-- Dumped from database version 12.4
-- Dumped by pg_dump version 12.4
......
-- Name: test2; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.test2 (
id integer NOT NULL,
demark character varying(20)
);
ALTER TABLE public.test2 OWNER TO postgres;
--
-- Data for Name: test2; Type: TABLE DATA; Schema: public; Owner: postgres
--
INSERT INTO public.test2 VALUES
(1, 'postgres'),
(2, 'postgres');
INSERT INTO public.test2 VALUES
(3, 'postgres'),
(4, 'postgres');
INSERT INTO public.test2 VALUES
(5, 'postgres'),
(6, 'postgres');
......
(左右滑动查看完整内容)
二、pg_dumpall
| 序号 | 选项 | 说明 |
|---|---|---|
| 1 | –extra-float-digits | 如果为此参数指定了整数值,则在使用pg_dump命令获取数据之前执行“ SET extra_float_digits =指定值”语句。转储文件不包含SET语句。可以指定的值的范围是-15至3。如果指定了非数字值,则将其视为0。 |
| 2 | –exclude-database | 在PostgreSQL 12中,添加了–exclude-database选项。此选项指定要从备份中排除的数据库。指定多个数据库时,请使用与psql命令相同的模式。也可以多次指定相同的选项。 |
| 3 | –oids | 这个选项已经被移除. |
| 4 | 增加注释 | 注释已添加到输出文件中,用于用户设置(ALTER USER SET语句)和数据库设置。 |
##排除单个数据库
[postgres@host1 ~]$ pg_dumpall --exclude-database='test1' -f alldump.sql
##排除多个名字相近数据库
[postgres@host1 ~]$ pg_dumpall --exclude-database='test[12]' -f alldump.sql
##排除多个名字完全不同数据库
[postgres@host1 ~]$ pg_dumpall --exclude-database='a' --exclude-database='b' -f alldump.sql
-- User Configurations
-- User Config {User_name}
-- Databases
-- Database {Database_name} dump

文章转载自瀚高PG实验室,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




