> For the complete documentation index, see [llms.txt](https://docs.tonic.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tonic.ai/fabricate/data-masking/masking-db-reqs/postgresql.md).

# PostgreSQL

## Server and schema requirements

For PostgreSQL, Fabricate masking has the following server and schema requirements:

<table data-header-hidden><thead><tr><th width="234.06640625" valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top"><strong>Version</strong></td><td valign="top"><p>12 or later.</p><p><br>The major version for the destination database must be equal to or later than the source database version.</p></td></tr><tr><td valign="top"><strong>Encoding and locale</strong></td><td valign="top">The source and destination databases must have the same encoding and locale.</td></tr><tr><td valign="top"><strong>Extensions</strong></td><td valign="top">Every extension that is installed on the source database must be available for the destination database.</td></tr><tr><td valign="top"><strong>Transaction timeout</strong></td><td valign="top">For PostgreSQL 17 and later, for both the source and destination logins, <code>transaction_timeout = 0</code></td></tr></tbody></table>

Affected tables cannot have triggers that are marked `ENABLE ALWAYS` or `ENABLE REPLICA`. To check whether there are triggers that use these settings:

{% code overflow="wrap" %}

```sql
SELECT tgrelid::regclass AS table_name, tgname AS trigger_name,
         CASE tgenabled WHEN 'A' THEN 'ALWAYS' WHEN 'R' THEN 'REPLICA' END AS fires
  FROM pg_trigger
  WHERE NOT tgisinternal AND tgenabled IN ('A', 'R');
```

{% endcode %}

## General connection requirements

### Connect directly or through a pool in session mode

Do not use transaction or statement mode, such as:

* PgBouncer with `pool_mode = transaction`
* Supavisor on port 6543
* Neon `-pooler` hosts

### Password authentication only

Fabricate masking does not support client certificate authentication.

### TLS

TLS must be set to `require`, `verify-ca`, or `verify-full`.

You can use a custom certificate authority.

## Source database requirements

The source database must be on a primary server and not a replica.

### Required source database user permissions

The source database user must have the following permissions:

* &#x20; `USAGE` on the copied schemas
* &#x20; `SELECT` on every table and sequence
* &#x20; `REFERENCES` on every table.
* &#x20; `TEMPORARY` on the database
* &#x20; `BYPASSRLS` if any copied table uses row-level security

To grant the required privileges:

{% code overflow="wrap" %}

```sql
GRANT USAGE ON SCHEMA <schema> TO <user>;
GRANT SELECT, REFERENCES ON ALL TABLES IN SCHEMA <schema> TO <user>;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA <schema> TO <user>;
ALTER DEFAULT PRIVILEGES IN SCHEMA <schema> GRANT SELECT, REFERENCES ON TABLES TO <user>;
ALTER DEFAULT PRIVILEGES IN SCHEMA <schema> GRANT SELECT ON SEQUENCES TO <user>;
GRANT TEMPORARY ON DATABASE <database> TO <user>;
```

{% endcode %}

Where:

* `<schema>` is the name of a schema.
* `<user>` is the database user.
* `<database>` is the name of the source database.

### Objects that the source database cannot have

The source database cannot have the following objects:

* Foreign data wrappers or foreign servers
* Large objects
* Tables that use declarative partitioning or inheritance (INHERIT)

## Destination database requirements

### Destination database user requirements

The database user must be a superuser.

On a managed service that does not have a true superuser, such as Amazon RDS or Amazon Aurora, the user must have the following:

* `rds_superuser`
* `CREATE` and `TEMPORARY` on the target database
* Ownership of every target schema, table, and sequence

### Start with an empty destination database

Create the destination database as an empty database.

This enables the masking process to create the schema directly from the source database.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tonic.ai/fabricate/data-masking/masking-db-reqs/postgresql.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
