# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: PostgreSQL (with PostGIS and pgvector)
spec:
    description: PostgreSQL distribution with PostGIS (geospatial data) and pgvector (vector similarity search) extensions included.
    coverImage: https://supabase.com/_next/image?url=%2Fimages%2Fblog%2Fembeddings%2Fog_pgvector.png&w=1920&q=100&dpl=dpl_DY4LKyQnD4owmb9nd3CSxAqabF3m
    icon: https://cdn.zeabur.com/marketplace/postgresql.svg
    tags:
        - Database
        - pgvector
        - PostGIS
    readme: |
        PostgreSQL is a free and open-source relational database management system that emphasizes extensibility and SQL compliance. This template deploys PostgreSQL with two powerful extensions:

        - **PostGIS**: Adds support for storing, indexing, and querying geospatial data.
        - **pgvector**: Enables storing and searching vector embeddings for AI applications, similarity search, etc.

        ## Configuration

        This is a one-click deployment, so you rarely need to configure PostgreSQL after deployment. Both PostGIS and pgvector extensions should be available to be enabled in your database.
        - Enable pgvector extension
        ```sql
        CREATE EXTENSION IF NOT EXISTS vector;
        ```

        - Enable PostGIS extension
        ```sql
        CREATE EXTENSION IF NOT EXISTS postgis;
        ```

        ## Connection

        The "Instruction" section contains the root username, password, and the default database of your PostgreSQL instance. It also provides the connection string and command for you to **connect from outside**.

        If you want to access your PostgreSQL in your other services (**inter-service**), you can [reference](https://zeabur.com/docs/deploy/special-variables) the [exposed variable](https://zeabur.com/docs/deploy/customize-prebuilt#environment-variable) `POSTGRES_CONNECTION_STRING` in your service with `${POSTGRES_CONNECTION_STRING}`. For more flexible cases, you can reference these variables:

        - `POSTGRES_HOST`: The hostname of this PostgreSQL instance for **private networking**.
        - `POSTGRES_PORT`: The port of this PostgreSQL instance for **private networking**.
        - `POSTGRES_DATABASE`: The default database of this PostgreSQL instance.
        - `POSTGRES_USERNAME`: The default **root** username of this PostgreSQL instance.
        - `POSTGRES_PASSWORD`: The default **root** password of this PostgreSQL instance.

        If your project contains multiple PostgreSQL instances, the reference variable might be unreliable. In this case, manually specifying the PostgreSQL instance's hostname and port is recommended.

        To find your PostgreSQL instance's hostname and port for private networking, check the "Networking" tab of your PostgreSQL instance.
    services:
        - name: postgres-pgvector-postgis
          icon: https://www.gravatar.com/avatar/13f5f68d4c3448bdef716217cd0cd0cb?s=120&r=g&d=404
          template: PREBUILT
          spec:
            source:
                image: bryanlin16899/postgres-vector-postgis:17.4
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Connect Command (psql)
                  content: psql "postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgreSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgreSQL database
                  content: ${POSTGRES_DATABASE}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                PGDATA:
                    default: /var/lib/postgresql/data/pgdata
                POSTGRES_CONNECTION_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: zeabur_db
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: zeabur_user
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
localization:
    zh-CN:
        description: 包含 PostGIS（地理空间数据）和 pgvector（向量相似度搜索）扩展的 PostgreSQL。
        readme: |
            PostgreSQL 是一个免费且开源的关系型数据库管理系统，强调扩展性和 SQL 合规性。此模板部署的 PostgreSQL 包含两个强大的扩展：

            - **PostGIS**: 添加对存储、索引和查询地理空间数据的支持。
            - **pgvector**: 支持存储和搜索用于 AI 应用、相似性搜索等的向量嵌入。

            ## 设置

            考虑到这是一键部署，部署后你几乎不需要设置 PostgreSQL。PostGIS 和 pgvector 扩展应该都可以在您的数据库中启用。
            - 启用 pgvector 扩展
            ```sql
            CREATE EXTENSION IF NOT EXISTS vector;
            ```

            - 启用 PostGIS 扩展
            ```sql
            CREATE EXTENSION IF NOT EXISTS postgis;
            ```


            ## 连接

            「指引 (Instruction)」部分包含你 PostgreSQL 实例的 root 用户名、密码和默认数据库，也提供 **从外部连接** 的 connection string 及连接命令。

            如果你想在其他服务中取用你的 PostgreSQL（也就是在 **服务间互连**），可以[引用](https://zeabur.com/docs/zh-CN/deploy/special-variables) `POSTGRES_CONNECTION_STRING` [exposed variables](https://zeabur.com/docs/zh-CN/deploy/customize-prebuilt#environment-variable)，也就是 `${POSTGRES_CONNECTION_STRING}`。如果需要更灵活的情况，可以引用这些变量：

            - `POSTGRES_HOST`：这个 PostgreSQL 实例的 **内网** 主机名。
            - `POSTGRES_PORT`：这个 PostgreSQL 实例的 **内网** 连接端口。
            - `POSTGRES_DATABASE`：这个 PostgreSQL 实例的默认数据库。
            - `POSTGRES_USERNAME`：这个 PostgreSQL 实例的默认 **root** 用户名。
            - `POSTGRES_PASSWORD`：这个 PostgreSQL 实例的默认 **root** 密码。

            如果你的项目包含多个 PostgreSQL 实例，引用变量的结果可能会出现混乱（选择成另一个 PostgreSQL 实例的 exposed variables）。在这种情况下，建议自行指定 PostgreSQL 实例的主机名和连接端口。

            你可以在 PostgreSQL 实例中的「网络」选项卡中找到你的 PostgreSQL 可以用于内网通信的主机名和连接端口，其中主机名的后缀是 `zeabur.internal`。
    zh-TW:
        description: 包含 PostGIS（地理空間資料）和 pgvector（向量相似度搜尋）擴充功能的 PostgreSQL。
        readme: |-
            PostgreSQL 是一個免費且開源的關聯式資料庫管理系統，強調擴展性和 SQL 合規性。此模板部署的 PostgreSQL 包含兩個強大的擴充功能：

            - **PostGIS**: 新增對儲存、索引和查詢地理空間資料的支援。
            - **pgvector**: 支援儲存和搜尋用於 AI 應用程式、相似性搜尋等的向量嵌入。

            ## 設定

            PostGIS 和 pgvector 擴充功能應該都可以在您的資料庫中啟用。

            - 啟用 pgvector extensions
            ```sql
            CREATE EXTENSION IF NOT EXISTS vector;
            ```

            - 啟用 PostGIS extensions
            ```sql
            CREATE EXTENSION IF NOT EXISTS postgis;
            ```

            ## 連線

            「指引 (Instruction)」部分包含你 PostgreSQL 實體的 root 使用者名稱、密碼和預設資料庫，亦提供 **從外部連線** 的 connection string 及連線命令。

            如果你想在其他服務中取用你的 PostgreSQL（也就是在 **服務間互連**），可以[引用](https://zeabur.com/docs/zh-TW/deploy/special-variables) `POSTGRES_CONNECTION_STRING` [exposed variables](https://zeabur.com/docs/deploy/customize-prebuilt#environment-variable)，也就是 `${POSTGRES_CONNECTION_STRING}`。如果需要更靈活的情況，可以引用這些變數：

            - `POSTGRES_HOST`：這個 PostgreSQL 實體的 **內網** 主機名稱。
            - `POSTGRES_PORT`：這個 PostgreSQL 實體的 **內網** 連線埠。
            - `POSTGRES_DATABASE`：這個 PostgreSQL 實體的預設資料庫。
            - `POSTGRES_USERNAME`：這個 PostgreSQL 實體的預設 **root** 用戶名。
            - `POSTGRES_PASSWORD`：這個 PostgreSQL 實體的預設 **root** 密碼。

            如果你的專案包含多個 PostgreSQL 實體，引用變數的結果可能會亂跳（選成另一個 PostgreSQL 實體的 exposed variables）。在這種情況下，建議自行指定 PostgreSQL 實體的主機名稱和連線埠。

            你可以在 PostgreSQL 實體中的「網路」分頁中找到你 PostgreSQL 可以用來內網通訊的主機名稱和連線埠，其中主機名稱的後綴是 `zeabur.internal`。
