瀚高数据库
目录
文档用途
详细信息
文档用途
本文主要用于介绍与pg10.5相比,pg_dump/pg_dumpall命令的新增选项介绍。
详细信息
一、pg_dump
1、新增选项
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. | 
2、示例
① --on-conflict-do-nothing
[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
--② --rows-per-insert
[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、新增选项
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语句)和数据库设置。 | 
2、示例
① --exclude-database
[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②增加的注释,以下内容部分会出现在pg_dumpall导出的文本文件中.
-- User Configurations                
-- User Config {User_name}                
-- Databases                
-- Database {Database_name} dump









