# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: PostgreSQL(ParadeDB)
spec:
    description: ParadeDB is an Elasticsearch alternative based on Postgres, with built-in support for pg_search and pgvector.
    icon: https://cdn.zeabur.com/marketplace/postgresql.svg
    tags:
        - Database
    readme: |
        ParadeDB is an Elasticsearch alternative based on Postgres, with built-in support for pg_search and pgvector.

        This PostgreSQL distribution includes the pg_search and pgvector extensions, enabling full-text search and vector search capabilities in PostgreSQL. You can use "ParadeDB" to build full-text search and vector search applications.

        ## Configuration

        It is a one-click deployment, so you rarely need to configure PostgreSQL after deployment.

        You can configure PostgreSQL by editing the file `/etc/postgresql/postgresql.conf` with [Config Editor](https://zeabur.com/docs/deploy/config-edit). We have pre-configured some of the essential settings for you.

        ## 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 (it may pick the exposed variable of another PostgreSQL instance). 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, and you will see the hostname suffixed with `zeabur.internal` and the port that you can use to connect to this PostgreSQL instance.

        ## Restoring the backup

        Zeabur provides the automatic backup feature for PostgreSQL. However, you need to restore the backup manually. You can restore the backup by following the steps below:

        1. Download and extract the backup file from the backup storage. You will see a `data.sql` file.
        2. Find the "PostgreSQL Connect Command" in the "Instructions" section of your PostgreSQL instance.
        3. Make sure you have installed PostgreSQL client tools in your machine. Then, run:
           ```bash
           <Your PostgreSQL Connect Command> < data.sql
           ```

        Note that **restoring the backup also replaces the existing user password**. If you prefer to keep the existing user password, you should remove the `CREATE ROLE` and `ALTER ROLE` statement from the `data.sql` file before running the command.
    services:
        - name: ParadeDB
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            id: paradedb
            source:
                image: paradedb/paradedb:latest-pg17
            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
                  content: psql "postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL 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
                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: root
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
localization:
    zh-CN:
        description: ParadeDB 是一个基于 Postgres 的 Elasticsearch 替代品，其在 Postgres 的基础上内置了 pg_search 和 pgvector
        readme: |
            ParadeDB 是一个基于 Postgres 的 Elasticsearch 替代品，其在 Postgres 的基础上内置了 pg_search 和 pgvector。

            这个 PostgreSQL 发行版包含了 pg_search 和 pgvector 扩展功能，为 PostgreSQL 提供了全文搜索和向量搜索功能。你可以使用「ParadeDB」来构建全文搜索和向量搜索应用程序。

            ## 设置

            考虑到这是一键部署，部署后你几乎不需要设置 PostgreSQL。

            你可以通过使用 [Config Editor](https://zeabur.com/docs/zh-CN/deploy/config-edit) 编辑 `/etc/postgresql/postgresql.conf` 文件来设置 PostgreSQL。我们已经为您预先配置了必要的几个设置。

            ## 连接

            「指引 (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`。

            ## 还原备份

            Zeabur 提供 PostgreSQL 的自动备份功能。但是，你需要手动还原备份。你可以按照以下步骤还原备份：

            1. 从备份区下载并解压备份文件。你会看到一个 `data.sql` 文件。
            2. 在 PostgreSQL 实例的「指引」部分中找到「PostgreSQL Connect Command」。
            3. 确保你的机器上已安装 PostgreSQL 用户端工具。然后执行：
               ```bash
               <PostgreSQL Connect Command> < data.sql
               ```

            注意**还原备份也会取代现有用户密码**。如果你想保留现有用户密码，应在执行命令之前从 `data.sql` 文件中删除 `CREATE ROLE` 和 `ALTER ROLE` 语句。
    zh-TW:
        description: ParadeDB 是一個基於 Postgres 的 Elasticsearch 替代品，其在 Postgres 的基礎上內建了 pg_search 和 pgvector。
        readme: |
            ParadeDB 是一個基於 Postgres 的 Elasticsearch 替代品，其在 Postgres 的基礎上內建了 pg_search 和 pgvector。

            這個 PostgreSQL 發行版包含了 pg_search 和 pgvector 擴展功能，為 PostgreSQL 提供了全文搜尋和向量搜尋功能。你可以使用「ParadeDB」來構建全文搜尋和向量搜尋應用程式。

            ## 設定

            考慮到這是一鍵部署，部署後你幾乎不用設定 PostgreSQL。

            你可以透過使用 [Config Editor](https://zeabur.com/docs/zh-TW/deploy/config-edit) 編輯 `/etc/postgresql/postgresql.conf` 檔案來設定 PostgreSQL。我們已經幫您預先配好必要的幾個設定了。

            ## 連線

            「指引 (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`。

            ## 還原備份

            Zeabur 提供 PostgreSQL 的自動備份功能。但是，你需要手動還原備份。你可以按照以下步驟還原備份：

            1. 從備份區下載並解壓備份檔案。你會看到一個 `data.sql` 檔案。
            2. 在 PostgreSQL 實體的「指引」部分中找到「PostgreSQL Connect Command」。
            3. 確保你的機器上已安裝 PostgreSQL 用戶端工具。然後執行：
               ```bash
               <PostgreSQL Connect Command> < data.sql
               ```

            注意**還原備份也會取代現有使用者密碼**。如果你想保留現有使用者密碼，應在執行命令之前從 `data.sql` 檔案中刪除 `CREATE ROLE` 和 `ALTER ROLE` 語句。
