<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>惜分飞 &#187; PostgreSQL导入</title>
	<atom:link href="https://www.xifenfei.com/tag/postgresql%e5%af%bc%e5%85%a5/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Wed, 04 Nov 2026 15:33:30 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>PostgreSQL逻辑导出导入</title>
		<link>https://www.xifenfei.com/2018/08/postgresql-export-import.html</link>
		<comments>https://www.xifenfei.com/2018/08/postgresql-export-import.html#comments</comments>
		<pubDate>Fri, 03 Aug 2018 11:16:41 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL导入]]></category>
		<category><![CDATA[PostgreSQL导出]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=7644</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2018/08/postgresql-export-import.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2018/08/postgresql-export-import.html" target="_blank">PostgreSQL逻辑导出导入</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p><strong>pg_dump命令说明</strong></p>
<pre class="brush: bash; title: ; notranslate">
C:\Users\Administrator&gt;pg_dump --help
pg_dump 把一个数据库转储为纯文本文件或者是其它格式.

用法:
  pg_dump [选项]... [数据库名字]

一般选项:
  -f, --file=FILENAME          输出文件或目录名
  -F, --format=c|d|t|p         输出文件格式 (定制, 目录, tar)
                               明文 (默认值))
  -j, --jobs=NUM               执行多个并行任务进行备份转储工作
  -v, --verbose                详细模式
  -V, --version                输出版本信息，然后退出
  -Z, --compress=0-9           被压缩格式的压缩级别
  --lock-wait-timeout=TIMEOUT  在等待表锁超时后操作失败
  --no-sync                    do not wait for changes to be written safely to disk
  -?, --help                   显示此帮助, 然后退出

控制输出内容选项:
  -a, --data-only              只转储数据,不包括模式
  -b, --blobs                  在转储中包括大对象
  -B, --no-blobs               exclude large objects in dump
  -c, --clean                  在重新创建之前，先清除（删除）数据库对象
  -C, --create                 在转储中包括命令,以便创建数据库
  -E, --encoding=ENCODING      转储以ENCODING形式编码的数据
  -n, --schema=SCHEMA          只转储指定名称的模式
  -N, --exclude-schema=SCHEMA  不转储已命名的模式
  -o, --oids                   在转储中包括 OID
  -O, --no-owner               在明文格式中, 忽略恢复对象所属者

  -s, --schema-only            只转储模式, 不包括数据
  -S, --superuser=NAME         在明文格式中使用指定的超级用户名
  -t, --table=TABLE            只转储指定名称的表
  -T, --exclude-table=TABLE    不转储指定名称的表
  -x, --no-privileges          不要转储权限 (grant/revoke)
  --binary-upgrade             只能由升级工具使用
  --column-inserts             以带有列名的INSERT命令形式转储数据
  --disable-dollar-quoting     取消美元 (符号) 引号, 使用 SQL 标准引号
  --disable-triggers           在只恢复数据的过程中禁用触发器
  --enable-row-security        启用行安全性（只转储用户能够访问的内容）
  --exclude-table-data=TABLE   不转储指定名称的表中的数据
  --if-exists              当删除对象时使用IF EXISTS
  --inserts                    以INSERT命令，而不是COPY命令的形式转储数据
  --no-publications            do not dump publications
  --no-security-labels         不转储安全标签的分配
  --no-subscriptions           do not dump subscriptions
  --no-synchronized-snapshots  在并行工作集中不使用同步快照
  --no-tablespaces             不转储表空间分配信息
  --no-unlogged-table-data     不转储没有日志的表数据
  --quote-all-identifiers      所有标识符加引号，即使不是关键字
  --section=SECTION            备份命名的节 (数据前, 数据, 及 数据后)
  --serializable-deferrable   等到备份可以无异常运行
  --snapshot=SNAPSHOT          为转储使用给定的快照
  --strict-names               要求每个表和/或schema包括模式以匹配至少一个实体
  --use-set-session-authorization
                               使用 SESSION AUTHORIZATION 命令代替
                ALTER OWNER 命令来设置所有权

联接选项:
  -d, --dbname=DBNAME       对数据库 DBNAME备份
  -h, --host=主机名        数据库服务器的主机名或套接字目录
  -p, --port=端口号        数据库服务器的端口号
  -U, --username=名字      以指定的数据库用户联接
  -w, --no-password        永远不提示输入口令
  -W, --password           强制口令提示 (自动)
  --role=ROLENAME          在转储前运行SET ROLE

如果没有提供数据库名字, 那么使用 PGDATABASE 环境变量
的数值.

报告错误至 &lt;pgsql-bugs@postgresql.org&gt;.

C:\Users\Administrator&gt;
</pre>
<p><strong>导出环境准备</strong></p>
<pre class="brush: sql; title: ; notranslate">
C:\Users\Administrator&gt;psql -U u_xifenfei -d db_xifenfei
用户 u_xifenfei 的口令：
psql (10.4)
输入 &quot;help&quot; 来获取帮助信息.

db_xifenfei=# create table t_dump as select * from pg_tables;
SELECT 69
db_xifenfei=# insert into t_dump select * from t_dump;
INSERT 0 69
…………
db_xifenfei=# insert into t_dump select * from t_dump;
INSERT 0 565248
db_xifenfei=# create table public.t_dump_pub as select * from t_dump;
SELECT 1130496
db_xifenfei=# select count(*) from t_dump;
  count
---------
 1130496
(1 行记录)

db_xifenfei=# select count(*) from public.t_dump_pub;
  count
---------
 1130496
(1 行记录)
</pre>
<p><strong>导出命令</strong></p>
<pre class="brush: bash; title: ; notranslate">
pg_dump  -U u_xifenfei -f e:/u_xifenfei.sql db_xifenfei
pg_dump  -U u_xifenfei -f e:/u_xifenfei2.sql --inserts db_xifenfei
</pre>
<p><strong>psql导入说明</strong></p>
<pre class="brush: bash; title: ; notranslate">
C:\Users\Administrator&gt;psql -?
psql是PostgreSQL 的交互式客户端工具。
使用方法:
  psql [选项]... [数据库名称 [用户名称]]
通用选项:
  -c,--command=命令        执行单一命令(SQL或内部指令)然后结束
 -d, --dbname=数据库名称   指定要连接的数据库 (默认：&quot;Administrator&quot;)
  -f, --file=文件名      从文件中执行命令然后退出
  -l, --list             列出所有可用的数据库,然后退出
  -v, --set=, --variable=NAME=VALUE
                           设置psql变量NAME为VALUE
                           (例如，-v ON_ERROR_STOP=1)
  -V, --version            输出版本信息, 然后退出
  -X, --no-psqlrc         不读取启动文档(~/.psqlrc)
  -1 (&quot;one&quot;), --single-transaction
                          作为一个单一事务来执行命令文件(如果是非交互型的)
  -?, --help[=options]     显示此帮助，然后退出
      --help=commands      列出反斜线命令，然后退出
      --help=variables     列出特殊变量，然后退出

输入和输出选项：
  -a, --echo-all          显示所有来自于脚本的输入
  -b, --echo-errors        回显失败的命令
  -e, --echo-queries      显示发送给服务器的命令
 -E, --echo-hidden        显示内部命令产生的查询
  -L, --log-file=文件名  将会话日志写入文件
  -n, --no-readline       禁用增强命令行编辑功能(readline)
  -o, --output=FILENAME 将查询结果写入文件(或 |管道)
  -q, --quiet             以沉默模式运行(不显示消息，只有查询结果)
  -s, --single-step       单步模式 (确认每个查询)
  -S, --single-line        单行模式 (一行就是一条 SQL 命令)

输出格式选项 :
 -A, --no-align           使用非对齐表格输出模式
  -F, --field-separator=STRING
             为字段设置分隔符,用于不整齐的输出(默认：&quot;|&quot;)
  -H, --html             HTML 表格输出模式
  -P, --pset=变量[=参数]    设置将变量打印到参数的选项(查阅 \pset 命令)
  -R, --record-separator=STRING
             为不整齐的输出设置字录的分隔符(默认：换行符号)
  -t, --tuples-only      只打印记录i
  -T, --table-attr=文本   设定 HTML 表格标记属性（例如,宽度,边界)
  -x, --expanded           打开扩展表格输出
  -z, --field-separator-zero
                           为不整齐的输出设置字段分隔符为字节0
  -0, --record-separator-zero
                           为不整齐的输出设置记录分隔符为字节0

联接选项:
  -h, --host=主机名        数据库服务器主机或socket目录(默认：&quot;本地接口&quot;)
  -p, --port=端口        数据库服务器的端口(默认：&quot;5432&quot;)
  -U, --username=用户名    指定数据库用户名(默认：&quot;Administrator&quot;)
  -w, --no-password       永远不提示输入口令
  -W, --password           强制口令提示 (自动)

更多信息，请在psql中输入&quot;\?&quot;(用于内部指令)或者 &quot;\help&quot;(用于SQL命令)，
或者参考PostgreSQL文档中的psql章节.

臭虫报告至 &lt;pgsql-bugs@postgresql.org&gt;.
</pre>
<p><strong>导入操作</strong></p>
<pre class="brush: sql; title: ; notranslate">
C:\Users\Administrator&gt;psql -U u_xifenfei -d db_xifenfei 
用户 u_xifenfei 的口令：
psql (10.4)
输入 &quot;help&quot; 来获取帮助信息.

db_xifenfei=# create database test_pump;
CREATE DATABASE

C:\Users\Administrator&gt;psql -d test_pump -U u_xifenfei -f e:/u_xifenfei.sql
用户 u_xifenfei 的口令：
SET
SET
SET
SET
SET
 set_config
------------

(1 行记录)


SET
SET
SET
CREATE SCHEMA
ALTER SCHEMA
CREATE EXTENSION
COMMENT
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 1130496
COPY 1130496
</pre>
<p><strong>导出/导入数据核对</strong></p>
<pre class="brush: sql; title: ; notranslate">
C:\Users\Administrator&gt;psql -d test_pump -U u_xifenfei
用户 u_xifenfei 的口令：
psql (10.4)
输入 &quot;help&quot; 来获取帮助信息.

test_pump=# \d
                   关联列表
  架构模式  |    名称    |  类型  |   拥有者
------------+------------+--------+------------
 public     | t_dump_pub | 数据表 | u_xifenfei
 u_xifenfei | t_dump     | 数据表 | u_xifenfei
(2 行记录)
</pre>
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/08/postgresql-schema.html" rel="bookmark" class="crp_title">PostgreSQL模式理解</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/08/psql-fatal-no-pg_hba-conf-entry-for-host.html" rel="bookmark" class="crp_title">psql: FATAL:  no pg_hba.conf entry for host</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/08/pg-tablespace-database-schema.html" rel="bookmark" class="crp_title">PostgreSQL的表空间、数据库、用户之间的关系</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2018/08/pg_rman_backup_restore.html" rel="bookmark" class="crp_title">pg_rman 备份还原测试</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2015/06/postgresql%e7%ae%80%e5%8d%95%e6%93%8d%e4%bd%9c%e4%b9%8b-%e5%88%9b%e5%bb%ba%e5%ba%93%e7%99%bb%e5%bd%95ddldmlhelp%e7%99%bb%e5%87%ba.html" rel="bookmark" class="crp_title">PostgreSQL简单操作之&#8212;创建库,登录,ddl,dml,help,登出,删除库</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/12/pg-replace-oid-recovery.html" rel="bookmark" class="crp_title">PostgreSQL oid文件替换实现数据访问</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2013/08/oracle-12c-dbms_utility-expand_sql_text-%e6%9f%a5%e7%9c%8bsql%e8%a7%86%e5%9b%be%e5%9f%ba%e8%a1%a8.html" rel="bookmark" class="crp_title">ORACLE 12C dbms_utility.expand_sql_text 查看SQL视图基表</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/03/pdu-recovery-corrupt-block.html" rel="bookmark" class="crp_title">PostgreSQL表文件损坏恢复&#8212;pdu恢复损坏的表文件</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/08/%e5%9c%a8%e7%ba%bf%e9%87%8d%e5%ae%9a%e4%b9%89%e5%8e%9f%e7%90%86%e6%8e%a2%e8%ae%a8.html" rel="bookmark" class="crp_title">在线重定义原理探讨</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2025/09/pg-truncate-recovery.html" rel="bookmark" class="crp_title">Postgres数据库truncate表无有效备份恢复</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2010/09/shell%e7%bc%96%e7%a8%8b%e2%80%94%e2%80%94%e5%9f%ba%e6%9c%ac%e8%af%ad%e6%b3%95.html" rel="bookmark" class="crp_title">shell编程——基本语法</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/05/%e4%bd%bf%e7%94%a8dblink%e5%af%bc%e8%87%b4%e7%9a%84-opaque_transform.html" rel="bookmark" class="crp_title">使用dblink导致的/*+ OPAQUE_TRANSFORM */</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2018/08/postgresql-export-import.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
