暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

postgresql 数据库&表导入导出

原创 骆加坤 2024-06-19
182

数据库导出导入:

导出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

 

 

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论