数据库导出导入:
导出db01库到db01文件中:
../../bin/pg_dump -f db01 -d db01 -h 127.0.0.1 -p 5431 -U postgres -W
以上导出的db01文件导入到db011库中:
-bash-4.2$ ../bin/psql -f db01 -d db011 -p 5431 -h 127.0.0.1
Password for user postgres:
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
CREATE SCHEMA
ALTER SCHEMA
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 1
COPY 0
COPY 0
COPY 6
COPY 0
表导出导入:
导出库db01下的t01,t02表:
-bash-4.2$ ../bin/pg_dump -t public.t01 -t public.t02 -d db01 -f t01 -h 127.0.0.1 -p 5431 -U postgres -W
Password:
-bash-4.2$ cat t01
--
-- PostgreSQL database dump
--
-- Dumped from database version 14.10
-- Dumped by pg_dump version 14.10
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: t01; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.t01 (
id character varying(20)
);
ALTER TABLE public.t01 OWNER TO postgres;
--
-- Name: t02; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.t02 (
id integer
);
ALTER TABLE public.t02 OWNER TO postgres;
--
-- Data for Name: t01; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY public.t01 (id) FROM stdin;
a
b
c
c
d
\.
--
-- Data for Name: t02; Type: TABLE DATA; Schema: public; Owner: postgres
--
COPY public.t02 (id) FROM stdin;
1
2
3
\.
--
-- PostgreSQL database dump complete
--
将以上数据导入到 db011库下:
-bash-4.2$ ../bin/psql -d db011 -f t01 -h 127.0.0.1 -p 5431 -U postgres -W
Password:
SET
SET
SET
SET
SET
set_config
------------
(1 row)
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 5
COPY 3




