Tuesday, December 21, 2021

how to get DDL of table in postgreSQL using pg_dump

 how to get DDL of table in PostgreSQL

********************************************


<linux_server>:/var/opt/pgsql11/data/tablespace/app_tablespace> pg_dump -t 'public.phonebook' -d testdb

--

-- PostgreSQL database dump

--


-- Dumped from database version 11.6

-- Dumped by pg_dump version 12.1


SET statement_timeout = 0;

SET lock_timeout = 0;

SET idle_in_transaction_session_timeout = 0;

SET client_encoding = 'SQL_ASCII';

SET standard_conforming_strings = on;

SELECT pg_catalog.set_config('search_path', '', false);

SET check_function_bodies = false;

SET xmloption = content;

SET client_min_messages = warning;

SET row_security = off;


SET default_tablespace = '';


--

-- Name: phonebook; Type: TABLE; Schema: public; Owner: postgres

--


CREATE TABLE public.phonebook (

    phone character varying(32),

    firstname character varying(32),

    lastname character varying(32),

    address character varying(64)

);



ALTER TABLE public.phonebook OWNER TO postgres;


--

-- Data for Name: phonebook; Type: TABLE DATA; Schema: public; Owner: postgres

--


COPY public.phonebook (phone, firstname, lastname, address) FROM stdin;

+1 123 456 7890 John    Doe     North America

\.



--

-- PostgreSQL database dump complete

--


No comments:

Post a Comment