pg_net
Async HTTP Requests
Repository
supabase/pg_net
https://github.com/supabase/pg_net
Source
pg_net-0.20.2.tar.gz
pg_net-0.20.2.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_net | 0.20.2 | UTIL | Apache-2.0 | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4080 | pg_net | No | Yes | Yes | Yes | No | No | net |
| Related | http pg_curl pgjwt pg_smtp_client gzip bzip zstd pgjq |
|---|
patched 0.9.2 on el8/el9
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.20.2 | 1817161514 | pg_net | - |
| RPM | PIGSTY | 0.20.2 | 1817161514 | pg_net_$v | - |
| DEB | PIGSTY | 0.20.2 | 1817161514 | postgresql-$v-pg-net | - |
Build
You can build the RPM / DEB packages for pg_net using pig build:
pig build pkg pg_net # build RPM / DEB packages
Install
You can install pg_net directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_net; # Install for current active PG version
pig ext install -y pg_net -v 18 # PG 18
pig ext install -y pg_net -v 17 # PG 17
pig ext install -y pg_net -v 16 # PG 16
pig ext install -y pg_net -v 15 # PG 15
pig ext install -y pg_net -v 14 # PG 14
dnf install -y pg_net_18 # PG 18
dnf install -y pg_net_17 # PG 17
dnf install -y pg_net_16 # PG 16
dnf install -y pg_net_15 # PG 15
dnf install -y pg_net_14 # PG 14
apt install -y postgresql-18-pg-net # PG 18
apt install -y postgresql-17-pg-net # PG 17
apt install -y postgresql-16-pg-net # PG 16
apt install -y postgresql-15-pg-net # PG 15
apt install -y postgresql-14-pg-net # PG 14
Preload:
shared_preload_libraries = 'pg_net';
Create Extension:
CREATE EXTENSION pg_net;
Usage
The extension requires shared_preload_libraries = 'pg_net' in postgresql.conf.
GET Request
SELECT net.http_get('https://postman-echo.com/get?foo=bar') AS request_id;
With URL-encoded params and headers:
SELECT net.http_get(
'https://postman-echo.com/get',
params := '{"foo": "bar"}'::JSONB,
headers := '{"API-KEY": "<key>"}'::JSONB
) AS request_id;
POST Request
SELECT net.http_post(
'https://postman-echo.com/post',
'{"key": "value"}'::JSONB,
headers := '{"Content-Type": "application/json"}'::JSONB
) AS request_id;
Send a table row as payload:
WITH row AS (SELECT * FROM my_table LIMIT 1)
SELECT net.http_post(
'https://api.example.com/data',
to_jsonb(row.*)
) AS request_id
FROM row;
DELETE Request
SELECT net.http_delete('https://api.example.com/resource/42') AS request_id;
Checking Responses
SELECT * FROM net._http_response;
Configuration
SHOW pg_net.batch_size; -- default: 200, max rows processed per cycle
SHOW pg_net.ttl; -- default: 6 hours, response retention time
SHOW pg_net.database_name; -- default: 'postgres'
Modify settings:
ALTER SYSTEM SET pg_net.ttl TO '1 hour';
ALTER SYSTEM SET pg_net.batch_size TO 500;
SELECT pg_reload_conf();
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.