External tables enable accessing external data as if it were a regular database table. They are often used to move data into and out of a Greenplum database.
To create an external table definition, you specify the format of your input files and the location of your external data sources. For information about input file formats, see Formatting Data Files.
Use one of the following protocols to access external table data sources. You cannot mix protocols in
CREATE EXTERNAL TABLE statements:
file://accesses external data files on segment hosts that the Greenplum Database superuser (
gpadmin) can access. See file:// Protocol.
gpfdist://points to a directory on the file host and serves external data files to all Greenplum Database segments in parallel. See gpfdist:// Protocol.
gpfdists://is the secure version of
gpfdist. See gpfdists:// Protocol.
pxf://protocol accesses object store systems (Azure, Google Cloud Storage, Minio, S3), external Hadoop systems (HDFS, Hive, HBase), and SQL databases using the Greenplum Platform Extension Framework (PXF). See pxf:// Protocol.
s3://accesses files in an Amazon S3 bucket. See s3:// Protocol.
s3:// protocols are custom data access protocols, where the
gpfdists:// protocols are implemented internally in Greenplum Database. The custom and internal protocols differ in these ways:
s3://are custom protocols that must be registered using the
CREATE EXTENSIONcommand (
pxf) or the
CREATE PROTOCOLcommand (
s3). Registering the PXF extension in a database creates the
pxfprotocol. (See Accessing External Data with PXF.) To use the
s3protocol, you must configure the database and register the
s3protocol. (See Configuring the s3 Protocol.) Internal protocols are always present and cannot be unregistered.
pg_extprotocolcatalog table to specify the handler functions that implement the protocol. The protocol's shared libraries must have been installed on all Greenplum Database hosts. The internal protocols are not represented in the
pg_extprotocoltable and have no additional libraries to install.
GRANT [SELECT | INSERT | ALL] ON PROTOCOL. To allow (or deny) users permissions on the internal protocols, you use
ALTER ROLEto add the
NOCREATEEXTTABLE) attribute to each user's role.
External tables access external files from within the database as if they are regular database tables. External tables defined with the
s3 protocols utilize Greenplum parallelism by using the resources of all Greenplum Database segments to load or unload data. The
pxf protocol leverages the parallel architecture of the Hadoop Distributed File System to access files on that system. The
s3 protocol utilizes the Amazon Web Services (AWS) capabilities.
You can query external table data directly and in parallel using SQL commands such as
SORT EXTERNAL TABLE DATA, and you can create views for external tables.
The steps for using external tables are:
Define the external table.
Do one of the following:
Place the data files in the correct locations.
Query the external table with SQL commands.
Greenplum Database provides readable and writable external tables:
Readable external tables for data loading. Readable external tables support:
WHEREclause, it may be passed to the external data source. Refer to the gp_external_enable_filter_pushdown server configuration parameter discussion for more information. Note that this feature is currently supported only with the
pxfprotocol (see pxf:// Protocol). Readable external tables allow only
Writable external tables for data unloading. Writable external tables support:
External tables can be file-based or web-based. External tables using the
file:// protocol are read-only tables.
http://protocol or by running OS commands or scripts. External web tables are not rescannable: the data can change while the query runs.
Greenplum Database backup and restore operations back up and restore only external and external web table definitions, not the data source data.
file://protocol is used in a URI that specifies the location of an operating system file.
gpfdist://protocol is used in a URI to reference a running
gpfdists://protocol is a secure version of the
pxf://protocol to access data residing in object store systems (Azure, Google Cloud Storage, Minio, S3), external Hadoop systems (HDFS, Hive, HBase), and SQL databases.
s3protocol is used in a URL that specifies the location of an Amazon S3 bucket and a prefix to use for reading or writing files in the bucket.
CREATE EXTERNAL TABLEcommand can contain only one protocol.
Parent topic: Working with External Data