# PostgreSQL Configuration for ONEWEB

This section describes how to **prepare and configure a PostgreSQL database** for use with the ONEWEB Platform.

Database preparation is a **mandatory prerequisite** before deploying ONEWEB archives, as the platform requires predefined schemas, roles, and initial data to function correctly.

***

#### Configuration Overview

To configure PostgreSQL for ONEWEB, the following high‑level steps are required:

1. Create required **schemas and roles**
2. Configure **database user privileges**
3. Create **tables and initial data** for each ONEWEB component

Each step must be completed in sequence to ensure successful deployment and runtime operation.

***

#### Step 1: Create Schemas and Role Authorization

In this step, you create the database schemas and roles required by ONEWEB.

**Create Schemas**

Create the required database schemas for ONEWEB components by executing the following SQL script:

```
create_schema.sql
```

**Create Role Authorization**

Create database roles for ONEWEB applications by executing:

```
create_role.sql
```

**Set Role Password**

Set or update passwords for the database roles by executing:

```
alter_password.sql
```

> These roles will be used by ONEWEB components to access their respective schemas.

***

#### Step 2: Restrict Database User Permissions

To improve security, database user privileges must be restricted appropriately.

In this step:

* Adjust administrator privileges
* Set the correct `search_path` for each user
* Restrict schema access based on component responsibility

Execute the following SQL script:

```
alter_priviledge.sql
```

This ensures that each ONEWEB component can access only the schemas it requires.

***

#### Step 3: Create Tables and Initial Data

After schemas and roles are prepared, create table structures and insert initial data for ONEWEB components.

The table below lists the required schemas and corresponding SQL scripts.

| Schema       | Description                                                                                     |
| ------------ | ----------------------------------------------------------------------------------------------- |
| `eaf_master` | Create table structure and insert initial data using `ONEWEB.AR.4.0.19.12.base.postgres.sql`    |
| `iam2`       | Create table structure and insert initial data using `ONEWEB.IAM.4.0.19.12.base.postgres.sql`   |
| `mfd`        | Create table structure and insert initial data using `ONEWEB.MFD.4.0.0.19.12.base.postgres.sql` |
| `pd`         | Create table structure and insert initial data using `ONEWEB.PD.4.0.0.19_12.base.postgres.sql`  |
| `bpm`        | Create table structure and insert initial data using `ONEWEB.PR.4.0.0.19.12.base.postgres.sql`  |
| `asp`        | Create table structure and insert initial data using `ONEWEB.ASP.4.0.19.12.base.postgres.sql`   |
| `dpc2`       | Table structure is created automatically during application installation                        |
| `page`       | Create table structure and insert initial data using `ONEWEB.PGD.4.0.19.12.base.postgres.sql`   |
| `dashboard`  | Create table structure and insert initial data using `ONEWEB.DSHB.4.0.19.12.base.postgres.sql`  |

> Ensure that each SQL script is executed against the correct schema.

***

#### Security and Best‑Practice Notes

* Always restrict database privileges to the **minimum required**
* Avoid using superuser roles for application access
* Ensure schema ownership and role assignments are consistent with ONEWEB component usage
* Validate database connectivity after completing all steps

***

#### Completion Checklist

Before proceeding with ONEWEB deployment, verify that:

* All required schemas are created
* Database roles and passwords are configured
* Privileges are restricted correctly
* Tables and initial data are created successfully
* Database connections can be established from ONEWEB runtime

***

#### Reference

For PostgreSQL installation and administration details, refer to the official documentation:

* <https://www.postgresql.org/docs/9.3/tutorial-install.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onewebstack.com/oneweb-platform-th/getting-started/platform-configuration/platform-components-overview-and-management/prepare-prerequisite-software/prepare-database-server/postgresql-configuration-for-oneweb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
