简体   繁体   中英

How to remove comments and settings from pg_dump output?

I am trying to dump only data from a PostgreSQL database using pg_dump and then to restore those data into another one. But generating sql script with this tool also add some comments and settings into the output file.

Running this command :

pg_dump --column-inserts --data-only my_db > my_dump.sql

I get something like :

--
-- PostgreSQL database dump
--

-- Dumped from database version 8.4.22
-- Dumped by pg_dump version 10.8 (Ubuntu 10.8-0ubuntu0.18.04.1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET escape_string_warning = off;
SET row_security = off;

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

INSERT INTO public.....

Is there any way to avoid pg_dump generating those comments and settings ? I could do a small script to remove every lines before the first insert but it also generates comments everywhere on the file and I am sure there is a cleaner way to proceed but found nothing.

I don't think there is. I'd simply pipe through grep to filter out lines that start with the comment delimiter:

pg_dump --column-inserts --data-only my_db | grep -v "^--" > my_dump.sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM