http

HTTP client for PostgreSQL, allows web page retrieval inside the database.

Overview

PackageVersionCategoryLicenseLanguage
pg_http1.7.2UTILMITC
IDExtensionBinLibLoadCreateTrustRelocSchema
4070httpNoYesNoYesNoNo-
Relatedpg_net pg_curl pgjwt pg_smtp_client gzip bzip zstd pgjq pgmb
Depended Bypgmb

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG1.7.21817161514pg_http-
RPMPGDG1.7.21817161514pgsql_http_$v-
DEBPGDG1.7.21817161514postgresql-$v-http-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Build

You can build the RPM packages for pg_http using pig build:

pig build pkg pg_http         # build RPM packages

Install

You can install pg_http directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_http;          # Install for current active PG version
pig ext install -y pg_http -v 18  # PG 18
pig ext install -y pg_http -v 17  # PG 17
pig ext install -y pg_http -v 16  # PG 16
pig ext install -y pg_http -v 15  # PG 15
pig ext install -y pg_http -v 14  # PG 14
dnf install -y pgsql_http_18       # PG 18
dnf install -y pgsql_http_17       # PG 17
dnf install -y pgsql_http_16       # PG 16
dnf install -y pgsql_http_15       # PG 15
dnf install -y pgsql_http_14       # PG 14
apt install -y postgresql-18-http   # PG 18
apt install -y postgresql-17-http   # PG 17
apt install -y postgresql-16-http   # PG 16
apt install -y postgresql-15-http   # PG 15
apt install -y postgresql-14-http   # PG 14

Create Extension:

CREATE EXTENSION http;

Usage

Sources:

http lets PostgreSQL issue synchronous HTTP requests through libcurl. It is useful for controlled integrations and administrative calls, but the backend waits for the remote service inside the SQL statement and transaction. Restrict who can call it, set short timeouts, and do not let untrusted input choose arbitrary URLs.

Core Workflow

CREATE EXTENSION http;

SELECT status, content_type, content
FROM http_get('https://httpbingo.org/get');

Send JSON and inspect the response:

SELECT status, content::jsonb
FROM http_post(
  'https://httpbingo.org/post',
  '{"event":"invoice.paid"}',
  'application/json'
);

The generic entry point accepts a complete request:

SELECT (http((
  'GET',
  'https://httpbingo.org/headers',
  http_headers('Authorization', 'Bearer example'),
  NULL,
  NULL
)::http_request)).status;

Important Objects

  • http_request contains method, uri, headers, content_type, and content.
  • http_response contains status, content_type, headers, and content.
  • http_header, http_header(...), and http_headers(...) build request headers; unnest(response.headers) exposes response headers as rows.
  • http(...) executes a complete http_request.
  • http_get, http_post, http_put, http_patch, http_delete, and http_head are convenience wrappers.
  • urlencode(text) and urlencode(jsonb) encode query data.
  • http_set_curlopt, http_list_curlopt, and http_reset_curlopt manage supported session-level libcurl settings.

Timeouts, Connections, and Security

Each request uses a fresh connection by default. Enable persistent connections only after measuring backend lifetime and remote-server behavior:

SET http.curlopt_timeout_ms = 1000;
SET http.curlopt_connecttimeout_ms = 250;
SET http.curlopt_tcp_keepalive = 1;

The default request timeout is five seconds. A timeout raises a SQL error, so callers must handle transaction rollback. Network latency in triggers or long transactions can hold locks and exhaust database connections; prefer an outbox plus an external worker for durable asynchronous delivery.

Keep TLS verification enabled, protect credential-bearing curl settings, validate response status and content before use, and limit outbound destinations at both SQL privilege and network layers. Version 1.7.2 contains build, test, and curl-option constant maintenance relative to 1.7.1; it does not introduce a material SQL API change. The control file still declares SQL extension version 1.7.


Last Modified 2026-07-23: update extension list to 555 (d81fc56)