# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: PostgreSQL with TLS
spec:
    description: A free and open-source relational database management system emphasizing extensibility and SQL compliance with self-signed TLS certificate
    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.

        This image is based on [railwayapp-templates/postgres-ssl](https://github.com/railwayapp-templates/postgres-ssl) with some modification for Zeabur (see [zeabur/postgres-ssl](https://github.com/zeabur/postgres-ssl)). Thanks a lot to them!

        ## Configuration

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

        It contains a self-signed TLS certificate and might be much safer than connecting directly.

        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.
    services:
        - name: postgresql
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: pan93412/postgresql-ssl:17
            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
            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 = 100
                    shared_buffers = 128MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'Etc/UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'Etc/UTC'
                    lc_messages = 'en_US.utf8'
                    lc_monetary = 'en_US.utf8'
                    lc_numeric = 'en_US.utf8'
                    lc_time = 'en_US.utf8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: 493
                  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.
    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` というサフィックスが付いており、接続に使用できるポートが表示されます。
    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`。
    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`。
