Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CREATE EXTERNAL CONNECTION

CREATE EXTERNAL CONNECTION registra uma conexão reutilizável para um provider externo. A conexão pode ser usada por SERVER, FDW, FCW, backup ou execução remota.

CREATE EXTERNAL CONNECTION csv_local
PROVIDER csv
WITH (root = '/data/csv');

As opções da conexão definem o contexto comum de acesso. Opções específicas de um arquivo ou recurso devem ficar no objeto consumidor, normalmente a tabela estrangeira:

CREATE SERVER csv_files CONNECTION csv_local;

CREATE FOREIGN TABLE people_csv (
  id int8,
  name text
)
SERVER csv_files
WITH (
  file = 'people.csv',
  delimiter = ',',
  header = true,
  quote = '"'
);

Credenciais são referenciadas por CREATE SECRET:

CREATE EXTERNAL CONNECTION aws_prod
PROVIDER aws
WITH (
  credentials = SECRET aws_credentials,
  region = 'us-east-1'
);

SECRET name is a reference, not the credential value. The server resolves the secret when it validates or opens the provider; the catalog stores only the reference. Logical dumps currently include external connection and server definitions only when their option lists are empty; opaque provider options are not written because they may contain credentials. Such definitions are omitted with a warning. If an omitted definition has tags, the dump fails rather than silently losing those tags. Secret values are never included.

Foreign table definitions, comments, and tags are included in full plain/custom dumps when their server and connection are safely restorable. Foreign table rows are not copied. Options whose names suggest credentials must use a SECRET reference; otherwise the dump stops instead of writing a possible credential to the archive. Provision referenced secrets on the target first.

Connection definitions remain in the catalog after a server restart. The provider validates its options and implements its capabilities; the core only stores the definition and routes operations to that provider.

O provider é responsável por validar as opções e implementar as capacidades que oferecer. O núcleo apenas armazena a definição e encaminha a conexão ao provider correspondente.