http
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_http | 1.7.2 | UTIL | MIT | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4070 | http | No | Yes | No | Yes | No | No | - |
| Related | pg_net pg_curl pgjwt pg_smtp_client gzip bzip zstd pgjq pgmb |
|---|---|
| Depended By | pgmb |
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.7.2 | 1817161514 | pg_http | - |
| RPM | PGDG | 1.7.2 | 1817161514 | pgsql_http_$v | - |
| DEB | PGDG | 1.7.2 | 1817161514 | postgresql-$v-http | - |
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_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.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.