http
pg_http : HTTP client for PostgreSQL, allows web page retrieval inside the database.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4070 | http
|
pg_http
|
1.7.2 |
UTIL
|
MIT
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--s-d--
|
No
|
Yes
|
No
|
Yes
|
no
|
no
|
| Relationships | |
|---|---|
| Need By | pgmb
|
| See Also | pg_net
pg_curl
pgjwt
pg_smtp_client
gzip
bzip
zstd
pgjq
pgmb
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG
|
1.7.2 |
18
17
16
15
14
|
pg_http |
- |
| RPM | PGDG
|
1.7.2 |
18
17
16
15
14
|
pgsql_http_$v |
- |
| DEB | PGDG
|
1.7.2 |
18
17
16
15
14
|
postgresql-$v-http |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
el8.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
el9.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
el9.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
el10.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
el10.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
d12.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
d12.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
d13.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
d13.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
u22.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
u22.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
u24.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
u24.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
u26.x86_64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
u26.aarch64
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
PGDG 1.7.2
|
Source
pig build pkg pg_http; # build rpmInstall
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pg_http; # install via package name, for the active PG version
pig install http; # install by extension name, for the current active PG version
pig install http -v 18; # install for PG 18
pig install http -v 17; # install for PG 17
pig install http -v 16; # install for PG 16
pig install http -v 15; # install for PG 15
pig install http -v 14; # install for PG 14Create this extension with:
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_requestcontainsmethod,uri,headers,content_type, andcontent.http_responsecontainsstatus,content_type,headers, andcontent.http_header,http_header(...), andhttp_headers(...)build request headers;unnest(response.headers)exposes response headers as rows.http(...)executes a completehttp_request.http_get,http_post,http_put,http_patch,http_delete, andhttp_headare convenience wrappers.urlencode(text)andurlencode(jsonb)encode query data.http_set_curlopt,http_list_curlopt, andhttp_reset_curloptmanage 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.