How to remove comments and settings from pg_dump output?
Asked Answered
N

1

9

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.

Noletta answered 20/6, 2019 at 8:31 Comment(0)
D
3

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
Dutybound answered 21/6, 2019 at 6:5 Comment(1)
Yes finaly I did it using sed with sed -i '/^SET/d' dump.sql so I aceept your answer which is equivalent !Noletta

© 2022 - 2024 — McMap. All rights reserved.