# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: PostgreSQL:alpine
spec:
    description: A free and open-source relational database management system emphasizing extensibility and SQL compliance.
    coverImage: https://kinsta.com/wp-content/uploads/2022/03/what-is-postgresql.png
    icon: https://cdn.zeabur.com/marketplace/postgresql.svg
    tags:
        - Database
    readme: |
        A free and open-source relational database management system that emphasizes extensibility and SQL compliance.

        ## 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: postgresql
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: postgres:18-alpine
                command:
                    - docker-entrypoint.sh
                    - -c
                    - config_file=/etc/postgresql/postgresql.conf
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/18/docker
            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/18/docker/pgdata
                    expose: false
                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
            configs:
                - path: /etc/postgresql/postgresql.conf
                  template: |
                    # https://github.com/postgres/postgres/blob/master/src/backend/utils/misc/postgresql.conf.sample
                    listen_addresses = '*'
                    max_connections = 256
                    shared_buffers = 256MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'UTC'
                    lc_messages = 'en_US.UTF-8'
                    lc_monetary = 'en_US.UTF-8'
                    lc_numeric = 'en_US.UTF-8'
                    lc_time = 'en_US.UTF-8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
localization:
    es-ES:
        description: Un sistema de gestión de bases de datos relacional gratuito y de código abierto que enfatiza la extensibilidad y el cumplimiento de SQL
        readme: |
            Un sistema de gestión de bases de datos relacional gratuito y de código abierto que enfatiza la extensibilidad y el cumplimiento de SQL.

            ## Configuración

            Es una implementación con un solo clic, por lo que rara vez necesitas configurar PostgreSQL después de la implementación.

            Puedes configurar PostgreSQL editando el archivo `/etc/postgresql/postgresql.conf` con [Config Editor](https://zeabur.com/docs/es-ES/deploy/config-edit). Hemos preconfigurado algunos de los ajustes esenciales para ti.

            ## Conexión

            La sección "Instrucciones" contiene el nombre de usuario root, la contraseña y la base de datos predeterminada de tu instancia de PostgreSQL. También proporciona la cadena de conexión y el comando para **conectarse desde fuera**.

            Si deseas acceder a tu PostgreSQL en tus otros servicios (**entre servicios**), puedes [referenciar](https://zeabur.com/docs/es-ES/deploy/special-variables) la [variable expuesta](https://zeabur.com/docs/es-ES/deploy/customize-prebuilt#environment-variable) `POSTGRES_CONNECTION_STRING` en tu servicio con `${POSTGRES_CONNECTION_STRING}`. Para casos más flexibles, puedes referenciar estas variables:

            - `POSTGRES_HOST`: El nombre del host de esta instancia de PostgreSQL para **redes privadas**.
            - `POSTGRES_PORT`: El puerto de esta instancia de PostgreSQL para **redes privadas**.
            - `POSTGRES_DATABASE`: La base de datos predeterminada de esta instancia de PostgreSQL.
            - `POSTGRES_USERNAME`: El nombre de usuario **root** predeterminado de esta instancia de PostgreSQL.
            - `POSTGRES_PASSWORD`: La contraseña **root** predeterminada de esta instancia de PostgreSQL.

            Si tu proyecto contiene varias instancias de PostgreSQL, la variable de referencia podría ser poco confiable (podría elegir la variable expuesta de otra instancia de PostgreSQL). En este caso, se recomienda especificar manualmente el nombre del host y el puerto de la instancia de PostgreSQL.

            Para encontrar el nombre del host y el puerto de tu instancia de PostgreSQL para la red privada, revisa la pestaña "Redes" de tu instancia de PostgreSQL, y verás el nombre del host con el sufijo `zeabur.internal` y el puerto que puedes usar para conectarte a esta instancia de PostgreSQL.

            ## Restaurar la copia de seguridad

            Zeabur proporciona la función de copia de seguridad automática para PostgreSQL. Sin embargo, debes restaurar la copia de seguridad manualmente. Puedes restaurar la copia de seguridad siguiendo los pasos a continuación:

            1. Descarga y extrae el archivo de copia de seguridad del almacenamiento de copia de seguridad. Verás un archivo `data.sql`.
            2. Encuentra el "Comando de conexión de PostgreSQL" en la sección "Instrucciones" de tu instancia de PostgreSQL.
            3. Asegúrate de haber instalado las herramientas de cliente de PostgreSQL en tu máquina. Luego, ejecuta:
               ```bash
               <Tu comando de conexión de PostgreSQL> < data.sql
               ```

            Ten en cuenta que **restaurar la copia de seguridad también reemplaza la contraseña de usuario existente**. Si prefieres mantener la contraseña de usuario existente, debes eliminar la declaración `CREATE ROLE` y `ALTER ROLE` del archivo `data.sql` antes de ejecutar el comando.
    ja-JP:
        description: 拡張性と SQL 準拠を強調した、無料でオープンソースのリレーショナルデータベース管理システム
        readme: |
            拡張性と SQL 準拠を強調した、無料でオープンソースのリレーショナルデータベース管理システムです。

            ## 設定

            ワンクリックでデプロイできるため、デプロイ後に PostgreSQL を設定する必要はほとんどありません。

            [Config Editor](https://zeabur.com/docs/ja-JP/deploy/config-edit) を使用して、`/etc/postgresql/postgresql.conf` ファイルを編集することで PostgreSQL を設定できます。必要な設定の一部はあらかじめ設定済みです。

            ## 接続

            「Instruction」セクションには、PostgreSQL インスタンスの root ユーザー名、パスワード、およびデフォルトのデータベースが含まれており、**外部から接続**するための接続文字列とコマンドも提供されています。

            他のサービスで PostgreSQL を使用する場合（**サービス間接続**）、`${POSTGRES_CONNECTION_STRING}` として [exposed variables](https://zeabur.com/docs/ja-JP/deploy/customize-prebuilt#environment-variable) の `POSTGRES_CONNECTION_STRING` を[参照](https://zeabur.com/docs/ja-JP/deploy/special-variables)できます。より柔軟な使用ケースでは、以下の変数を参照することができます：

            - `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 インスタンスの「Instructions」セクションで「PostgreSQL Connect Command」を見つけます。
            3. マシンに PostgreSQL クライアントツールがインストールされていることを確認してから、次のコマンドを実行します：
               ```bash
               <PostgreSQL Connect Command> < data.sql
               ```

            **バックアップの復元は既存のユーザーパスワードも置き換えます**。既存のユーザーパスワードを保持したい場合は、コマンドを実行する前に `data.sql` ファイルから `CREATE ROLE` および `ALTER ROLE` ステートメントを削除する必要があります。
    zh-CN:
        description: 一个免费且开源的关系型数据库管理系统，强调扩展性和 SQL 合规性
        readme: |
            一个免费且开源的关系型数据库管理系统，强调扩展性和 SQL 合规性。

            ## 设置

            考虑到这是一键部署，部署后你几乎不需要设置 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: 一個免費且開源的關聯式資料庫管理系統，強調擴展性和 SQL 合規性
        readme: |
            一個免費且開源的關聯式資料庫管理系統，強調擴展性和 SQL 合規性。

            ## 設定

            考慮到這是一鍵部署，部署後你幾乎不用設定 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` 語句。
