geoip
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
geoip | 0.3.0 | GIS | BSD 2-Clause | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1560 | geoip | No | Yes | No | Yes | No | No | geoip |
| Related | ip4r postgis tzf country postgis_topology postgis_raster postgis_sfcgal postgis_tiger_geocoder address_standardizer |
|---|
no pg17 on el9, no legacy branch on el8
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | MIXED | 0.3.0 | 1817161514 | geoip | ip4r |
| RPM | PIGSTY | 0.3.0 | 1817161514 | geoip_$v | - |
| DEB | PIGSTY | 0.3.0 | 1817161514 | postgresql-$v-geoip | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.3.0 el8.x86_64.pg18 : geoip_18 geoip_18-0.3.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.3.0 el8.x86_64.pg17 : geoip_17 geoip_17-0.3.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.3.0 el8.x86_64.pg16 : geoip_16 geoip_16-0.3.0-1PIGSTY.el8.x86_64.rpm
| PIGSTY 0.3.0 | PIGSTY 0.3.0 |
| el8.aarch64 | PIGSTY 0.3.0 el8.aarch64.pg18 : geoip_18 geoip_18-0.3.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.3.0 el8.aarch64.pg17 : geoip_17 geoip_17-0.3.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.3.0 el8.aarch64.pg16 : geoip_16 geoip_16-0.3.0-1PIGSTY.el8.aarch64.rpm
| PIGSTY 0.3.0 | PIGSTY 0.3.0 |
| el9.x86_64 | PIGSTY 0.3.0 el9.x86_64.pg18 : geoip_18 geoip_18-0.3.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.3.0 el9.x86_64.pg17 : geoip_17 geoip_17-0.3.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.3.0 el9.x86_64.pg16 : geoip_16 geoip_16-0.3.0-1PIGSTY.el9.x86_64.rpm
| PIGSTY 0.3.0 | PIGSTY 0.3.0 |
| el9.aarch64 | PIGSTY 0.3.0 el9.aarch64.pg18 : geoip_18 geoip_18-0.3.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.3.0 el9.aarch64.pg17 : geoip_17 geoip_17-0.3.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.3.0 el9.aarch64.pg16 : geoip_16 geoip_16-0.3.0-1PIGSTY.el9.aarch64.rpm
| PIGSTY 0.3.0 | PIGSTY 0.3.0 |
| el10.x86_64 | PIGSTY 0.3.0 el10.x86_64.pg18 : geoip_18 geoip_18-0.3.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.3.0 el10.x86_64.pg17 : geoip_17 geoip_17-0.3.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.3.0 el10.x86_64.pg16 : geoip_16 geoip_16-0.3.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.3.0 el10.x86_64.pg15 : geoip_15 geoip_15-0.3.0-1PIGSTY.el10.x86_64.rpm
| PIGSTY 0.3.0 el10.x86_64.pg14 : geoip_14 geoip_14-0.3.0-1PIGSTY.el10.x86_64.rpm
|
| el10.aarch64 | PIGSTY 0.3.0 el10.aarch64.pg18 : geoip_18 geoip_18-0.3.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.3.0 el10.aarch64.pg17 : geoip_17 geoip_17-0.3.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.3.0 el10.aarch64.pg16 : geoip_16 geoip_16-0.3.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.3.0 el10.aarch64.pg15 : geoip_15 geoip_15-0.3.0-1PIGSTY.el10.aarch64.rpm
| PIGSTY 0.3.0 el10.aarch64.pg14 : geoip_14 geoip_14-0.3.0-1PIGSTY.el10.aarch64.rpm
|
| d12.x86_64 | PIGSTY 0.3.0 d12.x86_64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.3.0 d12.x86_64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.3.0 d12.x86_64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.3.0 d12.x86_64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~bookworm_amd64.deb
| PIGSTY 0.3.0 d12.x86_64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~bookworm_amd64.deb
|
| d12.aarch64 | PIGSTY 0.3.0 d12.aarch64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.3.0 d12.aarch64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.3.0 d12.aarch64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.3.0 d12.aarch64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~bookworm_arm64.deb
| PIGSTY 0.3.0 d12.aarch64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~bookworm_arm64.deb
|
| d13.x86_64 | PIGSTY 0.3.0 d13.x86_64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.3.0 d13.x86_64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.3.0 d13.x86_64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.3.0 d13.x86_64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~trixie_amd64.deb
| PIGSTY 0.3.0 d13.x86_64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~trixie_amd64.deb
|
| d13.aarch64 | PIGSTY 0.3.0 d13.aarch64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.3.0 d13.aarch64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.3.0 d13.aarch64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.3.0 d13.aarch64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~trixie_arm64.deb
| PIGSTY 0.3.0 d13.aarch64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~trixie_arm64.deb
|
| u22.x86_64 | PIGSTY 0.3.0 u22.x86_64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.3.0 u22.x86_64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.3.0 u22.x86_64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.3.0 u22.x86_64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~jammy_amd64.deb
| PIGSTY 0.3.0 u22.x86_64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~jammy_amd64.deb
|
| u22.aarch64 | PIGSTY 0.3.0 u22.aarch64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.3.0 u22.aarch64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.3.0 u22.aarch64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.3.0 u22.aarch64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~jammy_arm64.deb
| PIGSTY 0.3.0 u22.aarch64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~jammy_arm64.deb
|
| u24.x86_64 | PIGSTY 0.3.0 u24.x86_64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~noble_amd64.deb
| PIGSTY 0.3.0 u24.x86_64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~noble_amd64.deb
| PIGSTY 0.3.0 u24.x86_64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~noble_amd64.deb
| PIGSTY 0.3.0 u24.x86_64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~noble_amd64.deb
| PIGSTY 0.3.0 u24.x86_64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~noble_amd64.deb
|
| u24.aarch64 | PIGSTY 0.3.0 u24.aarch64.pg18 : postgresql-18-geoip postgresql-18-geoip_0.3.0-1PIGSTY~noble_arm64.deb
| PIGSTY 0.3.0 u24.aarch64.pg17 : postgresql-17-geoip postgresql-17-geoip_0.3.0-1PIGSTY~noble_arm64.deb
| PIGSTY 0.3.0 u24.aarch64.pg16 : postgresql-16-geoip postgresql-16-geoip_0.3.0-1PIGSTY~noble_arm64.deb
| PIGSTY 0.3.0 u24.aarch64.pg15 : postgresql-15-geoip postgresql-15-geoip_0.3.0-1PIGSTY~noble_arm64.deb
| PIGSTY 0.3.0 u24.aarch64.pg14 : postgresql-14-geoip postgresql-14-geoip_0.3.0-1PIGSTY~noble_arm64.deb
|
Build
You can build the RPM / DEB packages for geoip using pig build:
pig build pkg geoip # build RPM / DEB packages
Install
You can install geoip 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 geoip; # Install for current active PG version
pig ext install -y geoip -v 18 # PG 18
pig ext install -y geoip -v 17 # PG 17
pig ext install -y geoip -v 16 # PG 16
pig ext install -y geoip -v 15 # PG 15
pig ext install -y geoip -v 14 # PG 14
dnf install -y geoip_18 # PG 18
dnf install -y geoip_17 # PG 17
dnf install -y geoip_16 # PG 16
dnf install -y geoip_15 # PG 15
dnf install -y geoip_14 # PG 14
apt install -y postgresql-18-geoip # PG 18
apt install -y postgresql-17-geoip # PG 17
apt install -y postgresql-16-geoip # PG 16
apt install -y postgresql-15-geoip # PG 15
apt install -y postgresql-14-geoip # PG 14
Create Extension:
CREATE EXTENSION geoip CASCADE; -- requires: ip4r
Usage
This extension provides IP-based geolocation — you provide an IPv4 or IPv6 address and the extension looks up country, city, GPS coordinates, ASN and more. It requires the ip4r extension and GeoLite2 data from MaxMind.
CREATE EXTENSION ip4r;
CREATE EXTENSION geoip;
Functions
| Function | Description |
|---|---|
geoip_country_code(ip4|ip6) | Returns country code (2 chars) |
geoip_country(ip4|ip6) | Returns all country info (code, name, network) |
geoip_city_location(ip4|ip6) | Returns just the location ID (INT) |
geoip_city(ip4|ip6) | Returns all city info (GPS, ZIP code, etc.) |
geoip_asn(ip4|ip6) | Returns ASN name and IP range |
Examples
SELECT geoip_country_code('78.45.133.255'::ip4);
-- CZ
SELECT * FROM geoip.geoip_city('78.45.133.255'::ip4);
-- geoname_id | country_iso_code | city_name | postal_code | ...
-- ------------+------------------+-----------+-------------+----
-- 3066399 | CZ | Sardice | 696 13 | ...
SELECT * FROM geoip.geoip_country('78.45.133.255'::ip4);
-- network | country_iso_code | country_name
-- ----------------+------------------+--------------
-- 78.45.128.0/17 | CZ | Czechia
SELECT * FROM geoip.geoip_asn('78.45.133.255'::ip4);
-- network | asn_number | asn_name
-- --------------+------------+---------------------
-- 78.44.0.0/15 | 6830 | Liberty Global B.V.
Loading Data
The extension requires GeoLite2 CSV data from MaxMind. Download the City, Country, and ASN datasets in CSV format from MaxMind GeoLite2, then load:
cat GeoLite2-Country-Locations-en.csv | \
psql $DBNAME -c 'COPY geoip.geoip_country_locations FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-Country-Blocks-IPv4.csv | \
psql $DBNAME -c 'COPY geoip.geoip_country_blocks FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-Country-Blocks-IPv6.csv | \
psql $DBNAME -c 'COPY geoip.geoip_country_blocks FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-City-Locations-en.csv | \
psql $DBNAME -c 'COPY geoip.geoip_city_locations FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-City-Blocks-IPv4.csv | \
psql $DBNAME -c 'COPY geoip.geoip_city_blocks FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-City-Blocks-IPv6.csv | \
psql $DBNAME -c 'COPY geoip.geoip_city_blocks FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-ASN-Blocks-IPv4.csv | \
psql $DBNAME -c 'COPY geoip.geoip_asn_blocks FROM stdin WITH (FORMAT CSV, HEADER)'
cat GeoLite2-ASN-Blocks-IPv6.csv | \
psql $DBNAME -c 'COPY geoip.geoip_asn_blocks FROM stdin WITH (FORMAT CSV, HEADER)'
The “locations” files have multiple language variants — pick the one that works for you.
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.