12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 1. In a SQL client connected to Materialize, use the [`CREATE SECRET`](/sql/create-secret/)
- command to securely store the password for the `materialize` PostgreSQL user you
- created [earlier](#2-create-a-publication-and-a-replication-user):
- ```mzsql
- CREATE SECRET pgpass AS '<PASSWORD>';
- ```
- 1. Use the [`CREATE CONNECTION`](/sql/create-connection/) command to create a
- connection object with access and authentication details for Materialize to
- use:
- ```mzsql
- CREATE CONNECTION pg_connection TO POSTGRES (
- HOST '<host>',
- PORT 5432,
- USER 'materialize',
- PASSWORD SECRET pgpass,
- SSL MODE 'require',
- DATABASE '<database>'
- );
- ```
- - Replace `<host>` with your PostgreSQL endpoint.
- - Replace `<database>` with the name of the database containing the tables
- you want to replicate to Materialize.
- 1. Use the [`CREATE SOURCE`](/sql/create-source/) command to connect Materialize
- to your PostgreSQL instance and start ingesting data from the publication you
- created [earlier](#2-create-a-publication-and-a-replication-user):
- ```mzsql
- CREATE SOURCE mz_source
- IN CLUSTER ingest_postgres
- FROM POSTGRES CONNECTION pg_connection (PUBLICATION 'mz_source')
- FOR ALL TABLES;
- ```
- By default, the source will be created in the active cluster; to use a
- different cluster, use the `IN CLUSTER` clause. To ingest data from
- specific schemas or tables in your publication, use `FOR SCHEMAS
- (<schema1>,<schema2>)` or `FOR TABLES (<table1>, <table2>)` instead of `FOR
- ALL TABLES`.
- 1. After source creation, you can handle upstream [schema changes](/sql/create-source/postgres/#schema-changes)
- for specific replicated tables using the [`ALTER SOURCE...ADD SUBSOURCE`](/sql/alter-source/#context)
- and [`DROP SOURCE`](/sql/alter-source/#dropping-subsources) syntax.
|