|
1 | 1 | # PostGIS |
2 | 2 |
|
3 | | -TODO |
| 3 | +[PostGIS](https://postgis.net/) is an open-source geospatial database extension for PostgreSQL. |
| 4 | + |
| 5 | +This image provides a convenient way to deploy and manage `PostGIS` with |
| 6 | +[CloudNativePG](https://cloudnative-pg.io/). |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +### 1. Add the PostGIS extension image to your Cluster |
| 11 | + |
| 12 | +Define the `PostGIS` extension under the `postgresql.extensions` section of |
| 13 | +your `Cluster` resource. For example: |
| 14 | + |
| 15 | +```yaml |
| 16 | +apiVersion: postgresql.cnpg.io/v1 |
| 17 | +kind: Cluster |
| 18 | +metadata: |
| 19 | + name: cluster-postgis |
| 20 | +spec: |
| 21 | + imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie |
| 22 | + instances: 1 |
| 23 | + |
| 24 | + storage: |
| 25 | + size: 1Gi |
| 26 | + |
| 27 | + postgresql: |
| 28 | + extensions: |
| 29 | + - name: postgis |
| 30 | + image: |
| 31 | + reference: ghcr.io/cloudnative-pg/postgis-extension:3.6.0-18-trixie |
| 32 | + ld_library_path: |
| 33 | + - system |
| 34 | +``` |
| 35 | +
|
| 36 | +### 2. Enable the extension in a database |
| 37 | +
|
| 38 | +You can install `PostGIS` in a specific database by creating or updating a |
| 39 | +`Database` resource. For example, to enable it in the `app` database: |
| 40 | + |
| 41 | +```yaml |
| 42 | +apiVersion: postgresql.cnpg.io/v1 |
| 43 | +kind: Database |
| 44 | +metadata: |
| 45 | + name: cluster-postgis-app |
| 46 | +spec: |
| 47 | + name: app |
| 48 | + owner: app |
| 49 | + cluster: |
| 50 | + name: cluster-postgis |
| 51 | + extensions: |
| 52 | + - name: postgis |
| 53 | + ensure: present |
| 54 | + - name: postgis_raster |
| 55 | + ensure: present |
| 56 | + - name: postgis_sfcgal |
| 57 | + ensure: present |
| 58 | + - name: fuzzystrmatch |
| 59 | + ensure: present |
| 60 | + - name: address_standardizer |
| 61 | + ensure: present |
| 62 | + - name: address_standardizer_data_us |
| 63 | + ensure: present |
| 64 | + - name: postgis_tiger_geocoder |
| 65 | + ensure: present |
| 66 | + - name: postgis_topology |
| 67 | + ensure: present |
| 68 | +``` |
| 69 | + |
| 70 | +### 3. Verify installation |
| 71 | + |
| 72 | +Once the database is ready, connect to it with `psql` and run: |
| 73 | + |
| 74 | +```sql |
| 75 | +\dx |
| 76 | +``` |
| 77 | + |
| 78 | +You should see `postgis`, `postgis_raster` (and so on) listed among the installed extensions. |
| 79 | + |
| 80 | + |
| 81 | +### 4. Verify OS dependencies are properly satisified |
| 82 | + |
| 83 | +PostGIS requires several OS dependencies that are being provided via the `/system` directory. |
| 84 | +CloudNativePG makes them available to PostgreSQL by adding the directory to LD_LIBRARY_PATH for the PostgreSQL process. |
| 85 | + |
| 86 | +To verify that all PostGIS shared libraries requirements are being properly satisfied, |
| 87 | +connect to the container and run: |
| 88 | + |
| 89 | +```bash |
| 90 | +cd /extensions/postgis/lib |
| 91 | +LD_LIBRARY_PATH=/extensions/postgis/system ldd address_standardizer* postgis* |
| 92 | +``` |
| 93 | + |
| 94 | +Make sure there are no missing shared libraries. |
0 commit comments