{"id":14968796,"url":"https://github.com/supabase/pg_netstat","last_synced_at":"2025-04-13T06:41:13.993Z","repository":{"id":59317874,"uuid":"527455684","full_name":"supabase/pg_netstat","owner":"supabase","description":"PostgreSQL extension to monitor database network traffic","archived":false,"fork":false,"pushed_at":"2023-01-14T10:45:04.000Z","size":35,"stargazers_count":257,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-11T21:21:31.553Z","etag":null,"topics":["extensions","pcap","postgresql","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supabase.png","metadata":{"funding":{"github":["supabase"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-22T07:23:56.000Z","updated_at":"2025-03-06T23:18:06.000Z","dependencies_parsed_at":"2023-02-09T19:10:25.893Z","dependency_job_id":null,"html_url":"https://github.com/supabase/pg_netstat","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_netstat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_netstat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_netstat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fpg_netstat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supabase","download_url":"https://codeload.github.com/supabase/pg_netstat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["extensions","pcap","postgresql","rust"],"created_at":"2024-09-24T13:40:35.003Z","updated_at":"2025-04-13T06:41:13.959Z","avatar_url":"https://github.com/supabase.png","language":"Rust","funding_links":["https://github.com/sponsors/supabase"],"categories":[],"sub_categories":[],"readme":"# `pg_netstat`\n\n---\n\n**Source Code**: \u003ca href=\"https://github.com/supabase/pg_netstat\" target=\"_blank\"\u003ehttps://github.com/supabase/pg_netstat\u003c/a\u003e\n\n---\n\n### Overview\n\n`pg_netstat` monitors your PostgreSQL database network traffic.\n\nThis extension runs a background worker to capture network packets on the Postgres port, and provides realtime network stats data by a view `pg_netstat`. It uses [libpcap](https://www.tcpdump.org/manpages/pcap.3pcap.html) to capture packets and aggregates at user-specified interval.\n\nThe `pg_netstat` view can contain at most **60** history rows and discards the oldest rows when it is full, so choose your interval wisely.\n\n### Usage\n\nYou can query realtime network stats through the `pg_netstat` view.\n\n```sql\nselect * from pg_netstat;\n```\n\nQuery result is like below:\n\n\u003cimg width=\"1287\" alt=\"image\" src=\"https://user-images.githubusercontent.com/19306324/211506046-a2116af8-26e3-4630-a059-774db23e1502.png\"\u003e\n\n\n### Installation\n\n**Prerequisites**\n\n- Before install this extension, you need to give network packet capture permission to Postgres binary. For example,\n\n  ```\n  sudo setcap cap_net_raw,cap_net_admin=eip /usr/local/pgsql/bin/postgres\n  ```\n\n- `libpcap` library should be installed too, for example,\n\n   ```\n   sudo apt-get install libpcap-dev\n   ```\n\nAfter that, we can then start the installation. Download this repo and set up [`pgx`](https://github.com/tcdi/pgx):\n\n```\ncargo install cargo-pgx\n```\n\nAfter pgx is set up, use below command to build the extension package:\n\n```\ncargo pgx package --pg-config ~/.pgx/14.5/pgx-install/bin/pg_config\n```\n\nThe extension is located at path `./target/release/pg_netstat-pg14`. For more information, please visit [pgx site](https://github.com/tcdi/pgx).\n\nChange `postgresql.conf` to enable below line:\n\n```\nshared_preload_libraries = 'pg_netstat' # (change requires restart)\n```\n\nRestart the server and install extension in database:\n\n```sql\ncreate extension pg_netstat;\n\n-- check everything is working\nselect * from pg_netstat;\n```\n\n### Configuration\n\nBelow are the configurations you can put in `postgresql.conf` file:\n\n1. `pg_netstat.devices` - Network device names to capture packets from, delimited by comma, maximum 4 devices, default is auto detect\n2. `pg_netstat.interval` - How often network packets to be collected (in seconds), default is `10`\n3. `pg_netstat.capture_loopback` - Whether capture packets on loopback device, default is `false`\n4. `pg_netstat.packet_wait_time` - How long to wait for network packets to be deliverd to collector (in seconds), default is `5`\n5. `pg_netstat.pcap_buffer_size` - pcap setting for buffer size (in bytes), default is `1000000`\n6. `pg_netstat.pcap_snaplen` - pcap setting for snapshot length (in bytes), default is `96`\n7. `pg_netstat.pcap_timeout` - pcap setting for packet buffer timeout (in milliseconds), default is `1000`\n\nYou can list network device name by running `ifconfig` command. For example, device name for 'localhost' is `lo`. The device auto detect will use the first device that is not a `loopback` network interface.\n\nThe most useful config is `pg_netstat.interval`, which defines the stats collection frequency. Its change can be reloaded from config file by using `pg_ctl` command:\n\n```\npg_ctl reload -D /path/to/pg-data\n```\n\nAll the others settings are at low level and you probably don't want to change them. For all the `pcap_*` settings, see details at https://www.tcpdump.org/manpages/pcap.3pcap.html.\n\n### Caveats \u0026 Limitations\n\n- Windows is not supported, that limitation inherits from `pgx`.\n- Currently only supports PostgreSQL v14 and v15, if you need other versions supported please [raise an issue](https://github.com/supabase/pg_netstat/issues).\n- Replication haven't tested yet, use at your own risk.\n\n### Contribution\n\nAll contributions, feature requests, bug report or ideas are welcomed.\n\n### License\n\n[Apache License Version 2.0](./LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase%2Fpg_netstat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupabase%2Fpg_netstat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase%2Fpg_netstat/lists"}