Skip to content

Commit c2fd16a

Browse files
author
Mike Swantek
committed
Script modifications, script order of operations and documentation adds
1 parent e7df29b commit c2fd16a

3 files changed

Lines changed: 244 additions & 79 deletions

File tree

docs/post_deployment_steps.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ az fabric capacity resume --capacity-name <capacity-name> --resource-group <rg-n
4646

4747
5. Open the **bronze** lakehouse and verify the `Files/documents` folder structure exists
4848

49+
> **PostgreSQL Mirroring:** If you enabled PostgreSQL mirroring, follow the detailed steps in [PostgreSQL mirroring](./postgresql_mirroring.md) to finalize the connection and mirror creation.
50+
4951
---
5052

5153
## 3. Verify AI Foundry Project

docs/postgresql_mirroring.md

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,118 @@
22

33
This guide explains how to complete PostgreSQL mirroring in Microsoft Fabric after deployment.
44

5+
## Automation status
6+
7+
What is automated today:
8+
9+
- PostgreSQL server prep (roles, grants, seed table, parameters).
10+
- Mirror creation **after** a Fabric connection exists (scripted).
11+
12+
What is still manual and why:
13+
14+
- Fabric connection creation is **portal-only** today. The public Fabric API does not currently expose a supported endpoint to create PostgreSQL connections, so the connection must be created in the UI to obtain a `connectionId`.
15+
16+
Once Fabric exposes a supported API for connection creation, this step can be fully automated.
17+
518
## Why a Fabric Connection Is Required
619

720
The Fabric mirroring API requires a Fabric "connection" object that stores the PostgreSQL endpoint and credentials. The mirror call only accepts a `connectionId` and database name, so a valid Fabric connection must exist before mirroring can be created.
821

922
## Prerequisites
1023

1124
- Deployment finished, and PostgreSQL Flexible Server exists.
12-
- Post-provision prep ran (it creates the `fabric_user` role and sets required PostgreSQL flags).
1325
- You can sign in to Fabric (app.fabric.microsoft.com) with access to the workspace.
26+
- PostgreSQL authentication mode is **PostgreSQL and Microsoft Entra authentication** (password auth enabled).
27+
- You have access to the Key Vault that stores the PostgreSQL secrets.
1428

1529
## Step 1: Confirm PostgreSQL Details
1630

1731
Get the PostgreSQL server FQDN and database name:
1832

1933
- FQDN: from `azd env get-value postgreSqlServerFqdn`
2034
- Database name: `postgres` (default) or your custom DB
35+
- Admin login: `pgadmin`
36+
- Fabric login: `fabric_user` (used by Fabric)
37+
- Fabric password: Key Vault secret `postgres-fabric-user-password`
38+
39+
## Step 2: Prepare the Database (Automated by Default)
40+
41+
The mirroring prep script configures the server and creates a seed table so Fabric always finds at least one table to replicate.
42+
43+
### Automated (recommended)
44+
45+
Run:
46+
47+
```powershell
48+
pwsh ./scripts/automationScripts/FabricWorkspace/Mirror/prepare_postgresql_for_mirroring.ps1
49+
```
50+
51+
If you are running from a non-VNet host and the Key Vault blocks public access, set:
52+
53+
```powershell
54+
$env:POSTGRES_TEMP_ENABLE_KV_PUBLIC_ACCESS = 'true'
55+
```
56+
57+
What it does now:
58+
59+
- Creates or validates the `fabric_user` role.
60+
- Ensures PostgreSQL auth modes are enabled (password + Entra).
61+
- Grants `azure_cdc_admin` and database permissions.
62+
- Creates a seed table: `public.fabric_mirror_seed` (owned by the mirroring user when created as `fabric_user`).
63+
- Uses `psql` fallback when `rdbms-connect` cannot install.
2164

22-
## Step 2: Create the Fabric Connection (UI)
65+
### Manual (only if automation fails)
66+
67+
Connect as `pgadmin@<server-name>` in the `postgres` database and run:
68+
69+
```sql
70+
CREATE ROLE "fabric_user" CREATEDB CREATEROLE LOGIN REPLICATION PASSWORD '<fabric_user_password>';
71+
GRANT azure_cdc_admin TO "fabric_user";
72+
GRANT CREATE ON DATABASE "postgres" TO "fabric_user";
73+
GRANT USAGE ON SCHEMA public TO "fabric_user";
74+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO "fabric_user";
75+
76+
CREATE TABLE IF NOT EXISTS public.fabric_mirror_seed (
77+
id bigserial PRIMARY KEY,
78+
created_at timestamptz NOT NULL DEFAULT now()
79+
);
80+
INSERT INTO public.fabric_mirror_seed (created_at)
81+
SELECT now()
82+
WHERE NOT EXISTS (SELECT 1 FROM public.fabric_mirror_seed);
83+
84+
ALTER TABLE public.fabric_mirror_seed OWNER TO "fabric_user";
85+
```
86+
87+
Update the Key Vault secret after you set the password (automation already does this unless it failed):
88+
89+
```powershell
90+
az keyvault secret set --vault-name <keyvault-name> --name postgres-fabric-user-password --value "<fabric_user_password>"
91+
```
92+
93+
> Ownership note: Fabric requires the mirror user to own tables. If you create tables as `pgadmin`, change ownership to `fabric_user`.
94+
95+
## Step 3: Create the Fabric Connection (UI)
2396

2497
1. Open the Fabric workspace.
2598
2. Go to **Settings** -> **Manage connections and gateways**.
2699
3. Select **New connection** -> **PostgreSQL**.
27100
4. Enter:
28-
- Server: PostgreSQL FQDN
29-
- Database: your database name
30-
- User: `fabric_user`
101+
- Server: PostgreSQL FQDN (example: `pg-<env>.postgres.database.azure.com`)
102+
- Database: `postgres` (or your custom DB)
103+
- User: `fabric_user@<server-name>` (example: `fabric_user@pg-dev031126a`)
31104
- Password: value from Key Vault secret `postgres-fabric-user-password`
32105
5. Save and copy the **Connection ID**.
33106

34-
## Step 3: Set the Connection ID in azd
107+
## Step 4: Set the Connection ID in azd
35108

36109
```powershell
37110
azd env set-value fabricPostgresConnectionId "<connection-id>"
38111
azd env set-value POSTGRES_DATABASE_NAME "postgres"
39112
```
40113

41-
## Step 4: Create the Mirror
114+
## Step 5: Create the Mirror
42115

43-
Run the mirror script:
116+
Run the mirror script (this is the automation step after the connection exists):
44117

45118
```powershell
46119
./scripts/automationScripts/FabricWorkspace/Mirror/create_postgresql_mirror.ps1
@@ -55,3 +128,19 @@ Run the mirror script:
55128

56129
- The deployment now skips the mirror step until a valid Fabric connection exists, so `azd up` will no longer fail on this step.
57130
- If you rotate passwords, update the Fabric connection in the workspace.
131+
132+
## Troubleshooting
133+
134+
### Invalid credentials
135+
136+
- Ensure PostgreSQL auth is **PostgreSQL and Microsoft Entra authentication** (password auth enabled).
137+
- Use `fabric_user@<server-name>` in the Fabric connection.
138+
- Verify the Key Vault secret matches the role password. Automation sets it unless it failed.
139+
140+
### Must be owner of table
141+
142+
If Fabric reports `must be owner of table <table>`:
143+
144+
```sql
145+
ALTER TABLE public.fabric_mirror_seed OWNER TO "fabric_user";
146+
```

0 commit comments

Comments
 (0)