pgsql_fdw english doc

pgsql_fdw

Top > pgsql_fdw


  1. Name
  2. Description
  3. Install
    1. Requirement
    2. Build module
    3. Create extension
    4. Uninstall
  4. How to use
    1. Create server
    2. Create user mapping
    3. Create foreign table
    4. Execute query
    5. Alter FDW options
    6. Connection management
  5. Vaild FDW options
  6. Restrictions
  7. Details
    1. libpq Options used internally
    2. Functions
  8. See also

Name

pgsql_fdw -- A foreign data wrapper fot external PostgreSQL servers.

Description

You can create foreign tables which point tables on external PostgreSQL servers. Then you can use those foreign tables like ordinary local tables in SELECT query to retrieve data from external data.

pgsql_fdw optimizes remote query to reduce amount of data to be transferred.

  • Replace unnecessary column reference with NULL literal.
  • Push some of WHERE clause down to remote server.

Foreign tables are read-only in PostgreSQL 9.1, so modifying foreign tables would cause error.

Install

This section describes how to install pgsql_fdw.

Requirement

PostgreSQL
9.1

Build module

Source code of PostgreSQL 9.1 or pgxs environment is required to build pgsql_fdw binary module. Please interpret x.y.z as the version you downloaded.

Building with source code

You need to extract source files of pgsql_fdw down to contrib directory of PostgreSQL which has already been built, and invoke make command.


Building with pgxs

You need to set USE_PGXS shell variable to build and install.


Create extension

pgsql_fdw conforms EXTENSION mechanism, which was introduced in PostgreSQL 9.1, so just need to invoke CREATE EXTENSION command to install pgsql_fdw to your database. You don't need to execute SQL script which has been installed into extension directory of your PostgreSQL installation. It's contrib modules style. To create pgsql_fdw extension, you need to be a superuser.


Uninstall

Executing DROP EXTENSION is the only thing you need to do to uninstall pgsql_fdw. If some objects which were created with pgsql_fdw exist, you need to drop them first, or use CASCADE option of DROP EXTENSION statement.

Following example shows how to drop pgsql_fdw extension and some related objects: a server, a user mapping and four foreign tables.


How to use

Here you see how to retrieve data on an external PostgreSQL server. This is just a sample, so please replace connection information and table definition to fit your environment.

Create server

First of all, become a superuser and execute CREATE SERVER command to create a server object which points target server. You can specify hostname, port number and database name of the external server here.


Create user mapping

Execute CREATE USER MAPPING command to create a user mapping object which links server and local user. Here you can specify username and password of external database user. Superuser privilege is required to this.


User mapping for "public" is used for local users who don't have explicit user mapping.


Create foreign table

Execute CREATE FOREIGN TABLE command to define a foreign table which points an external table. The syntax of CREATE FOREIGN TABLE is basically similar to syntax of CREATE TABLE, except that you need to specify server name. You can specify schema name and/or table name of external table as FDW option. Following example shows how to define a foreign table "remote_accounts", which points an external table "public.pgbench_accounts" on a server "remote_db".


Execute query

Now you can get external data by executing usual SELECT statement against foreign tables. You can execute any SELECT against foreign tables, but can't modify external data via foreign table.


Owner of a foreign table can allow other users to use the foreign table by executing GRANT statement, like ordinary tables.

EXPLAIN command shows actual query which is sent to external server for each foreign table. Following example shows a plan tree which is used to retrieve data from external table "pgbench_accounts" via a foreign table "remote_accounts".


Alter FDW options

You can change value of FDW options with ALTER statement. Following example shows how to change remote user's password. Note that SET is required to change value of existing option.


Connection management

pgsql_fdw establishes a connection in the first query which uses a foreign table on a foreign server. Established connection is reused by following queries, and even by following scans in same query, during local session. In other words, only one connection is established against a foreign server until you switch local user. You can see active connections via pgsql_fdw_connections view.


You can discard any active connection anytime by invoking pgsql_fdw_disconnect() with server oid and local user oid. You can discard all active connections with following query:


When local transaction aborts, pgsql_fdw discards all active connections automatically. This would prevent connection leak occurs with unexpected error. Connection will be established again automatically when a foreign server was accessed later.

Vaild FDW options

pgsql_fdw retrieves various information required for a query against a foreign table from FDW options of objects which are related to the foreign table.

Connection options

All libpq options except following can be used as connection opions. Only "user" and "password" are fore user mappings, and others are for foreign servers.

  • client_encoding
  • fallback_application_name
  • replication

See Database Connection Control Functions for details of libpq options. Note that omitted options are taken from environment variables of the user who started PostgreSQL server. Invalid options would be caught at once, but omission of required parameters and wrong values will be found when query was executed actually.

Object name optionsl

You can specify name and/or schema of external table as FDW options of a foreign table, "relname" and "nspname". They default to foreign table's name ans schema respectively.

Cursor option

With a FDW option "fetch_count", you can control the behavior of cursor used internally. It is used as number of rows fetched from external server at a time, and defualt to 10000. This option can be specified to foreign table and/or foreign server. If both of them has value, foreign table's setting is used.

Restrictions

There are some restrictions to use pgsql_fdw.

Foreign tables are read-only
Foreign tables are read-only for specification of PostgreSQL, so DMLs other than SELECT fail with error. In addition, VACUUM and ANALYZE don't handle foreign tables. Please connect external server directly to execute this kind of commands to external tables.
Management of connection and transaction
A connection is shared between scans which access same foreign server even those scans are in a local query, and pgsql_fdw starts a transaction only at the beginning of a connection. As a result, multiple scans in a local query might have inconsistent result from the viewpoint of transaction.

Details

This section describes advanced usage and internal details.

Internal use of libpq options

Some of libpq options are used internally. "client_encoding" is set to local encoding to retrieve external data properly. "fallback_application_name" is set to "pgsql_fdw" to allow remote DBAs to know originator of connections via pg_stat_activity and server log.

Functions

This extension provides pgsql_fdw_validator as a valiidator, and pgsql_fdw_handler as a handler. These are created automatically during CREATE EXTENSION statement.

See also

PostgreSQL Documents

Foreign DataCREATE FOREIGN DATA WRAPPERCREATE SERVERCREATE USER MAPPINGCREATE FOREIGN TABLEDatabase Connection Control Functions,



Top > pgsql_fdw

时间: 2024-09-27 12:23:10

pgsql_fdw english doc的相关文章

English learning

1.Strong recommend:   http://www.englishclub.com/   http://www.talkenglish.com/   http://www.putclub.com/   http://www.tingroom.com/ 2.Reading:   http://www.cdlponline.org/ (Audlt learning)   http://www.usalearns.org(Recommend)   http://www.rd.com/  

怎么用java实现doc文档模板插入数据和表格并导出?急急急,在线等

问题描述 怎么用java实现doc文档模板插入数据和表格并导出?急急急,在线等 我要实现一个模板导出功能,模板包含标题和文字内容,模板中间还有一个表格,和结尾文字.要实现动态添加标题文字,其中表格中内容部分动态添加数据,可能会有多种模板,区别是表格样子不同,都要添加内容,最后整个导出doc文件.有没有demo?各位大神?谢谢了先.下面图片中红色框住部分是要动态添加数据的地方,其他地方是模板原型. 解决方案 下面是我实现的方式,用poi工具. /** * * @param filePath 源文件

WPS实用教程 看乔峰如何破解PPT转DOC难题?

  又到了毕业的时候,江湖上最大的学校--武林学院里的毕业生又要开始忙着做论文.每年写毕业论文必定是一场教师与学生斗智斗勇.腥风血雨的战争,必定会引得无数英雄尽折腰.课堂笔记是写论文最重要的"参考文献",然而像乔峰这样武林学院的刺头,翘课都已经是家常便饭,更何况课堂笔记这种东西他连面都不曾见过的玩意,现在马上面临交毕业论文最后期限,但是他却不慌不忙的说:"笔记神马都是浮云,把老师的PPT课件全部COPY回去才是王道." 这样投机取巧的行为被郭靖.虚竹这类优等生嗤之以

用金山WPS将txt、doc、wps合并为一个文档的方法

   今天,我们将给大家讲解的是使用金山wps将不同格式的文档合并为一个文档的方法.在教程中,我们将我们常见的txt,doc,wps三种文档合并为一个文档,大家知道是怎么做到的吗?一起来看看今天的金山wps教程吧! 金山wps 利用金山WPS将txt,doc,wps合并为一个文档的方法: 1.先将这几篇文章放至一个目录下; 2.启动WPS文字; 3.点击 插入->文件,然后在插入文件中选择你要合并文档的目录,并将文件类型调为所有文件; 4.选择你想合并的文档,最后点击打开. 这样,我们就把几篇文

javascript 调用: html中使用javascript调用本地程序(exe,doc等)

第一次用到这个,做个记录,在html页面中调用本地程序:<html><head><script language="javascript">function Run(strPath){var objShell = new ActiveXObject("wscript.shell");objShell.exec(strPath);objShell = null;}</script></head><bod

DOC转换为HTML后的变化

转换 在Word 97中,当把DOC格式的文档存为HTML格式的文档时,Word会关闭文档,然后用超文本标记语言(HTML)格式应答.此后在Word中的显示方式与出现在Web浏览器中的方式类似.这时的创作环境不支持的格式和其他项目会从文件中删除.通过实践我们可以总结出转换时Word会更改或取消的内容,希望广大朋友注意: ●批注 系统会删除你用"插入"菜单中的"批注"命令插入的批注.不过,将文档保存为HTML文档后,你可以输入批注并显示"批注"样式

使用FlashPaper在线转换.doc为.swf

FlashPaper 是Macromedia推出的一款电子文档类工具!通过使用FlashPaper,可以将需要的文档通过简单的设置转换为SWF格式的Flash动画,原文档的排版样式和字体显示不会收到影响,这样做的好处是不论对方的平台和语言版本是什么,都可以自由的观看你所制作的电子文档动画,并可以进行自由的放大,缩小和打印,翻页等操作! 展示的效果就像百度的文库查看效果. Flashpaper的使用相信大多数人都知道,这里的Demo是用于在线转换 .doc文件转换为 .swf的flash文件. 其

PDF、ZIP、DOC链接的标注

pdf|链接 原文:http://www.maratz.com/blog/archives/2005/01/13/pdf-links-labeling/翻译:http://www.176so.com/past/2007/3/17/pdf_links_labeling/ css技巧之PDF.ZIP.DOC链接的标注 有时候我们希望能明确的用小图标来标明我们的超链接的类型.是一个zip文档还是一个pdf文件.这样访问者就知道他所要点击的这个链接是下载而不是打开另一个页面了.如果所有的人都使用IE7或

Linux 下 php 转DOC转PDF转SWF实现百度的文库预览功能

去年开发了一个OA系统,需要实现文档一键上传并实现在线预览,类似百度文库的功能. 系统环境:CentOs5.5 用到的工具:Openoffice 3 , Pdf2Swf tool , Jodconverter , FlexPaper 网上找了些资料,早有人已经实现了这样的功能,只不过是用JAVA来写的东东,PHP的没找着. 结合网上的资料根据实现操作经验. 纪录并总结一下: 整体思路如下: 实现步骤: 1. DOC上传   2. DOC转成PDF   3. PDF转成SWF  4. 显示 基于对