# PostgreSQL

> Connect a PostgreSQL database with a read-only user, pick tables, and sync with full reload, incremental or CDC; CDC requirements on self-managed Postgres, RDS, Cloud SQL, Neon and Supabase.

PostgreSQL needs the Starter plan or above. Data is copied into the workspace's own warehouse over a read-only connection; DataxLand never writes to your database.

## 1. Prepare a user

Create a dedicated, read-only user for DataxLand:

```sql
CREATE ROLE dataxland LOGIN PASSWORD '<strong password>';
GRANT USAGE ON SCHEMA public TO dataxland;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO dataxland;
```

If the database only accepts connections from specific IPs, allow the DataxLand server address (ask support for it).

## 2. Connect

1. **Data sources → Add source**, pick **PostgreSQL**.
2. Fill in **Host**, **Port** (default 5432), **Database name**, **Schema** (default `public`), **User** and **Password**. **SSL**: default, prefer, require or disable; use require when the database is outside your private network.
3. Click **Test connection**.
4. Under **Choose the tables to read**, tick the tables. Optional **Filter by date (optional)**: pick a date column, a from date and a to date to load only that range.
5. Add the source. The password is encrypted at rest and never shown again.

Change it later in the **Connection and tables → Edit connection** card; changes apply from the next refresh.

## 3. Sync modes

PostgreSQL supports all three: **Full**, **Incremental** (needs a cursor column such as `updated_at` and a primary key) and **CDC** (log-based). See [Sync modes and refresh schedules](/en/docs/concepts/sync-modes).

## CDC

CDC reads the change log (WAL) through logical replication, so it sees updated and deleted rows and allows refreshes as often as every 15 minutes. DataxLand creates its own `pgoutput` replication slot for the source; the first sync is a full load.

Click **Check CDC requirements** on the source page. Each item shows **Passed** or **Not passed**:

| Requirement | How to meet it |
| --- | --- |
| `wal_level = logical` | Set `wal_level = logical` and restart Postgres. RDS, Aurora: `rds.logical_replication = 1`. Cloud SQL: `cloudsql.logical_decoding = on`. Neon, Supabase: turn on Logical Replication in the project settings |
| REPLICATION privilege | `ALTER ROLE dataxland WITH REPLICATION;` (RDS: `GRANT rds_replication TO dataxland;`) |
| A free replication slot | Raise `max_replication_slots` or drop unused slots |
| Tables have a primary key or REPLICA IDENTITY FULL | Add a primary key, or `ALTER TABLE table_name REPLICA IDENTITY FULL;` |
| A publication can be created | The user owns the tables and has CREATE on the database, or an administrator creates it up front: `CREATE PUBLICATION publication_name FOR TABLE table_a, table_b;` |

### Monitor lag

Click **View CDC lag** to see how much WAL the slot is holding. When the slot holds more than 1 GB, the page warns **The CDC slot is holding more than 1 GB of WAL.**: refresh more often. A slot that has not synced for 7 days is dropped by DataxLand so it cannot fill your database's disk (you are warned from day 5); the next sync then does a full reload.

## Si investigates with SQL

On PostgreSQL, Si may run read-only SQL against the source while investigating, within a limit on the number of queries and their cost. You can run queries yourself too, under **Review proposal → Advanced: run SQL on the source**, with the **Estimate** and **Run on the database** buttons.

## Related

- [Connect your data](/en/docs/connect-data)
- [BigQuery](/en/docs/sources/bigquery)
- [Security and privacy](/en/docs/security-privacy)
