PostGIS
=======
.. raw:: html
`PostGIS `_ は、 PostgreSQLの非常に人気のオープンソース拡張機能であり、
GIS地理情報システムオブジェクトをデータベースに保存し、
SQLを介して照会するためのサポートを導入します。
.. Note::
このセクションでは、PostGISに精通していることを前提として、CloudNativePGを介してKubernetesでPostGISデータベースを使用して新しいPostgreSQLクラスターを作成する方法に関する基本情報を提供します。
CloudNativePGコミュニティは、維持される `PostgreSQL Container images `_
上にビルドされるコンテナイメージを維持します。詳細については、次をご覧ください。
-
`postgis-containers `_
-
`postgis-containers `_
PostGISクラスターに関する基本的な概念
-------------------------------------
概念的に、PostGISベースのPostgreSQLクラスターまたは単にPostGISクラスターは、他のPostgreSQLクラスターと似ています。唯一の違いは次のとおりです。
- PostGISおよび関連ライブラリのシステム内の存在
- PostGIS拡張機能のデータベース内の存在
CloudNativePGは不変アプリケーションコンテナに基づいているため、
PostGISをプロビジョニングする唯一の方法は、オペランドに使用するコンテナイメージに追加することです。
:ref:`Container Image Requirements ` は、これを実現する方法に関する詳細な手順を提供します。もっと簡単には、以下の例にあるように、コミュニティからのPostGISコンテナイメージを使用できます。
2番目のステップは、PostgreSQLデータベースに拡張機能をインストールすることです。これは2つの方法で行うことができます。
- アプリケーションデータベースにインストールします。これは、マイクロサービスアーキテクチャに従って、クラスターでホストするメインで唯一のデータベースです。または
- インスタンスがマルチプルのデータベースで共有されるモノリスアーキテクチャを採用する場合、
``template1``
データベースにインストールして、クラスター内に作成することになるすべてのデータベースで利用できるようにします
.. Note::
データベース内のマイクロサービスとモノリスアーキテクチャの詳細については、 :ref:`How many databases should be hosted in a single PostgreSQL instance? ` を参照してください。
または :ref:`Database import ` 。
PostGISで新しいPostgreSQLクラスターを作成する
---------------------------------------------
PostGIS 3.6を使用して新しいPostgreSQL
18クラスターを作成することにします。
最初のステップは、オペランドに適切なPostGISコンテナイメージを使用し、
``Cluster`` リソースの\ ``.spec.imageName``
オプションを適切に設定することです。
以下の
`postgis-example.yaml `_ は、PostGISクラスターの作成を行う方法に関するガイダンスを提供します。
.. Warning::
CloudNativePGでは構成より規約が適用されますが、本番用にシステムの構成とチューニングに時間を費やす必要があることを考慮してください。また、以下の例の`imageName` は、PostgreSQL 18の最新の利用可能なイメージを意図的にポイントしています。真の不変性を実現するには、特定のイメージ名、またはできればSHA256ダイジェストを使用する必要があります。または、提供されている
`image catalogs `_ を使用します。
.. code:: yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: postgis-example
spec:
instances: 1
imageName: ghcr.io/cloudnative-pg/postgis:18-3.6-system-trixie
storage:
size: 1Gi
postgresql:
parameters:
log_statement: ddl
- --
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: postgis-example-app
spec:
name: app
owner: app
cluster:
name: postgis-example
extensions:
- name: postgis
- name: postgis_topology
- name: fuzzystrmatch
- name: postgis_tiger_geocoder
この例では、 ``Database``
リソースの宣言的拡張管理を活用して、指定された拡張機能を\ ``app``
データベースに追加します。
.. Note::
詳細については、 :ref:`データベース内の拡張機能の管理 <データベース内の拡張機能の管理>` を参照してください。
``app``
データベースに接続することにより、コンテナ内にあるPostGISの利用可能なバージョンを簡単に確認できます。このドキュメントの値とは異なる値を取得する場合があります。
.. code:: console
$ kubectl cnpg psql postgis-example -- app
psql (18.1 (Debian 18.1-1.pgdg13+3))
Type "help" for help.
app=# SELECT * FROM pg_available_extensions WHERE name ~ ^postgis ORDER BY 1;
name | default_version | installed_version | comment
- -------------------------+-----------------+-------------------+------------------------------------------------------------
postgis | 3.6.0 | 3.6.0 | PostGIS geometry and geography spatial types and functions
postgis-3 | 3.6.0 | | PostGIS geometry and geography spatial types and functions
postgis_raster | 3.6.0 | | PostGIS raster types and functions
postgis_raster-3 | 3.6.0 | | PostGIS raster types and functions
postgis_sfcgal | 3.6.0 | | PostGIS SFCGAL functions
postgis_sfcgal-3 | 3.6.0 | | PostGIS SFCGAL functions
postgis_tiger_geocoder | 3.6.0 | 3.6.0 | PostGIS tiger geocoder and reverse geocoder
postgis_tiger_geocoder-3 | 3.6.0 | | PostGIS tiger geocoder and reverse geocoder
postgis_topology | 3.6.0 | 3.6.0 | PostGIS topology spatial types and functions
postgis_topology-3 | 3.6.0 | | PostGIS topology spatial types and functions
(10 rows)
次のステップは、 ``Database``
リソースにリストされている拡張機能が\ ``app``
データベースに正しくインストールされていることを確認することです。
.. code:: console
app=# \dx
List of installed extensions
Name | Version | Default version | Schema | Description
- -----------------------+---------+-----------------+------------+------------------------------------------------------------
fuzzystrmatch | 1.2 | 1.2 | public | determine similarities and distance between strings
plpgsql | 1.0 | 1.0 | pg_catalog | PL/pgSQL procedural language
postgis | 3.6.0 | 3.6.0 | public | PostGIS geometry and geography spatial types and functions
postgis_tiger_geocoder | 3.6.0 | 3.6.0 | tiger | PostGIS tiger geocoder and reverse geocoder
postgis_topology | 3.6.0 | 3.6.0 | topology | PostGIS topology spatial types and functions
最後に
.. code:: console
app=# SELECT postgis_full_version();
postgis_full_version
- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POSTGIS="3.6.0 4c1967d" [EXTENSION] PGSQL="180" GEOS="3.13.1-CAPI-1.19.2" PROJ="9.6.0 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/usr/share/proj/proj.
db" (compiled against PROJ 9.6.0) LIBXML="2.9.14" LIBJSON="0.18" LIBPROTOBUF="1.5.1" WAGYU="0.5.0 (Internal)" TOPOLOGY
(1 row)