# CREATE SOURCE: PostgreSQL (New Syntax)
Creates a new source from PostgreSQL 11+.
> **Disambiguation:** This page reflects the new syntax which allows Materialize to handle upstream DDL changes, specifically adding or dropping columns, without downtime. For the deprecated syntax, see the [old reference page](/sql/create-source/postgres/).
Creates a new source from PostgreSQL. Materialize
supports creating sources from PostgreSQL version 11+. Once a new source is created, you can CREATE TABLE FROM SOURCE from the source
to create the corresponding tables in Materialize and start the data ingestion
process.
## Prerequisites
To create a source from PostgreSQL 11+, you must first:
For details, see the PostgreSQL integration guides.
## Syntax To create a source from an external PostgreSQL: ```mzsql CREATE SOURCE [IF NOT EXISTS]Materialize natively supports the following PostgreSQL types (including the array type for each of the types):
boolbpcharbyteachardatedaterangefloat4float8int2int2vectorint4int4rangeint8int8rangeintervaljsonjsonbnumericnumrangeoidtexttimetimestamptimestamptztsrangetstzrangeuuidvarcharAvoid truncating upstream tables that are being replicated into Materialize. If a replicated upstream table is truncated, the corresponding subsource(s)/table(s) in Materialize becomes inaccessible and will not produce any data until it is recreated.
Instead of truncating, use an unqualified DELETE to remove all rows from
the upstream table:
DELETE FROM t;
PostgreSQL’s logical replication API does not provide a signal when users remove tables from publications. Because of this, Materialize relies on periodic checks to determine if a table has been removed from a publication, at which time it generates an irrevocable error, preventing any values from being read from the table.
However, it is possible to remove a table from a publication and then re-add it before Materialize notices that the table was removed. In this case, Materialize can no longer provide any consistency guarantees about the data we present from the table and, unfortunately, is wholly unaware that this occurred.
To mitigate this issue, if you need to drop and re-add a table to a publication, ensure that you remove the table/subsource from the source before re-adding it using theDROP SOURCE command.
### PostgreSQL replication slots
When you define a source, Materialize will automatically create a **replication
slot** in the upstream PostgreSQL database (see [PostgreSQL replication
slots](#postgresql-replication-slots)). Each source ingests the raw replication
stream data for all tables in the specified publication using **a single**
replication slot. This allows you to minimize the performance impact on the
upstream database as well as reuse the same source across multiple
materializations.
The name of the replication slot created by Materialize is prefixed with
`materialize_`. In Materialize, you can query the
`mz_internal.mz_postgres_sources` to find the replication slots created:
```mzsql
SELECT id, replication_slot FROM mz_internal.mz_postgres_sources;
```
```
id | replication_slot
---------+----------------------------------------------
u8 | materialize_7f8a72d0bf2a4b6e9ebc4e61ba769b71
```
> **Tip:** For PostgreSQL 13+, set a reasonable value
> for max_slot_wal_keep_size
> to limit the amount of storage used by replication slots.
If you stop using Materialize, or if either the Materialize instance or
> the PostgreSQL instance crash, delete any replication slots. You can query
> the mz_internal.mz_postgres_sources table to look up the name of the
> replication slot created for each source.
If you delete all objects that depend on a source without also dropping
> the source, the upstream replication slot remains and will continue to
> accumulate data so that the source can resume in the future. To avoid
> unbounded disk space usage, make sure to use DROP SOURCE or manually delete the replication slot.
To create a source from PostgreSQL 11+, you must first:
For details, see the PostgreSQL integration guides.
### Create a source {#create-source-example} Once you have configured the upstream PostgreSQL, network security, and created the connection, you can create the source. In this example, the PostgreSQL publication is `mz_source` and the connection to PostgreSQL is `pg_connection`. ```mzsql /* This example assumes: - In the upstream PostgreSQL, you have defined: - replication user and password with the appropriate access. - a publication named `mz_source` for the `public.items` and `public.orders` tables. - In Materialize: - You have created a secret for the PostgreSQL password. - You have defined the connection to the upstream PostgreSQL. - You have used the connection to create a source. For example (substitute with your configuration): CREATE SECRET pgpass AS '