レス
元トピ次レス
タイトル
Re: 問題ID: 34472
フォーラム
最強WEB問題集OSS-DB Silver
投稿ユーザ(投稿日)
(2020/5/5)
本文
例えばこんな環境があったとして
[code]
$ psql -h localhost -U postgres
psql (12rc1)
Type "help" for help.

postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | pingt_test | table | postgres
(1 row)

postgres=# \dt pingt_test
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | pingt_test | table | postgres
(1 row)

postgres=# select * from pingt_test;
id | name | comment
----+-------+---------
1 | 34472 | pg_dump
(1 row)
[/code]
「任意の指定したテーブルや、スキーマをバックアップできる」というのはこういうことです。ここではpostgresデータベースでのpingt_testテーブルだけを指定してバックアップしています。
[code]
$ pg_dump -h localhost -U postgres -t pingt_test
--
-- PostgreSQL database dump
--

-- Dumped from database version 12rc1
-- Dumped by pg_dump version 12rc1

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
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 = '';

SET default_table_access_method = heap;

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

CREATE TABLE public.pingt_test (
id integer,
name text,
comment text
);


ALTER TABLE public.pingt_test OWNER TO postgres;

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

COPY public.pingt_test (id, name, comment) FROM stdin;
1 34472 pg_dump
\.


--
-- PostgreSQL database dump complete
--
[/code]
データを含まない、スキーマだけ(-s:schema only)も指定できます。
[code]
$ pg_dump -h localhost -U postgres -t pingt_test -s
--
-- PostgreSQL database dump
--

-- Dumped from database version 12rc1
-- Dumped by pg_dump version 12rc1

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
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 = '';

SET default_table_access_method = heap;

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

CREATE TABLE public.pingt_test (
id integer,
name text,
comment text
);


ALTER TABLE public.pingt_test OWNER TO postgres;

--
-- PostgreSQL database dump complete
--
[/code]

ですので、

-----引用(始)-----

この書き方ではオプションにテーブルやスキーマを設定でき、バックアップを取得できるような意味にとらえられませんか?

-----引用(終)-----

そのように捉えて問題ないと思うのですが、意図が違いますかね?

レス一覧

元トピ次レス


Ping-tモバイルTOP

Copyright (c) 2010
Ping-t All rights reserved.