# UI Bakery Postgres

UI Bakery's Postgres is a hosted data source and structure management tool provided by UI Bakery. Follow [this guide for more details](https://docs.uibakery.io/extras/ui-bakery-postgres) on the available features.

## Default configuration

If your instance update is handled by the [update.sh script](https://docs.uibakery.io/install-and-update/updating-on-premise-version#update-to-the-latest-version), a new Docker container will automatically be created in your installation. You will not need to make any additional configurations to access UI Bakery Postgres.

## Custom configuration

When you update manually, add these container details to your Docker Compose file and restart the container:

* Add new container configuration <https://github.com/uibakery/self-hosted/blob/main/docker-compose.yml#L76>
* Restart UI Bakery

```
docker compose down
docker compose up -d
```

## Standalone Postgres instance

It is also possible to connect to a completely standalone Postgres instance.

* First, set up the Postgres instance of your choice. UI Bakery supports Postgres v16+.
* Setup default database and a user to connect to the server from UI Bakery:

```sql
CREATE DATABASE bakery;
CREATE ROLE bakery WITH LOGIN PASSWORD 'SECURE_PASSWORD';
ALTER ROLE bakery CREATEDB CREATEROLE;

# remove unnecessary default permissions
REVOKE TEMPORARY, CONNECT ON DATABASE bakery FROM PUBLIC;
REVOKE TEMPORARY, CONNECT ON DATABASE postgres FROM PUBLIC;
REVOKE TEMPORARY, CONNECT ON DATABASE template1 FROM PUBLIC;
GRANT CONNECT ON DATABASE bakery TO bakery;
```

{% hint style="warning" %}
The provided configuration is default and should be used cautiously. It is not intended as a security recommendation.
{% endhint %}

* Allow connection to the Postgres server from UI Bakery using the `pg_hba.conf` file.
* Finally, provide the following env variables for UI Bakery to connect to the database:

```bash
# data source container host
UI_BAKERY_INTERNAL_DATABASE_SERVICE_URL=http://datasource:6060/bakeryDatabase
UI_BAKERY_INTERNAL_DATABASE_HOST=Postgres host
UI_BAKERY_INTERNAL_DATABASE_PORT=Postgres port
UI_BAKERY_INTERNAL_DATABASE_USERNAME=bakery
UI_BAKERY_INTERNAL_DATABASE_PASSWORD=SECURE_PASSWORD # change to your password
UI_BAKERY_INTERNAL_DATABASE_DATABASE=bakery
UI_BAKERY_INTERNAL_DATABASE_SYNC_SIZE_INTERVAL=0 # not needed for on-prem instances
```

## Disable UI Bakery Postgres

If you prefer not to use the editor and database features in your instance, you can disable these functionalities with the following environment variable:

```bash
UI_BAKERY_INTERNAL_DATABASE_ENABLED=false
```
