1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 1. In the SQL client connected to Materialize, use the [`CREATE CONNECTION`](/sql/create-connection/#ssh-tunnel) command to create an SSH tunnel connection:
- ```mzsql
- CREATE CONNECTION ssh_connection TO SSH TUNNEL (
- HOST '<SSH_BASTION_HOST>',
- PORT <SSH_BASTION_PORT>,
- USER '<SSH_BASTION_USER>'
- );
- ```
- - Replace `<SSH_BASTION_HOST>` and `<SSH_BASTION_PORT`> with the public IP address and port of the SSH bastion host you created [earlier](#b-optional-configure-network-security).
- - Replace `<SSH_BASTION_USER>` with the username for the key pair you created for your SSH bastion host.
- 1. Get Materialize's public keys for the SSH tunnel connection:
- ```mzsql
- SELECT * FROM mz_ssh_tunnel_connections;
- ```
- 1. Log in to your SSH bastion host and add Materialize's public keys to the `authorized_keys` file, for example:
- ```sh
- # Command for Linux
- echo "ssh-ed25519 AAAA...76RH materialize" >> ~/.ssh/authorized_keys
- echo "ssh-ed25519 AAAA...hLYV materialize" >> ~/.ssh/authorized_keys
- ```
- 1. Back in the SQL client connected to Materialize, validate the SSH tunnel connection you created using the [`VALIDATE CONNECTION`](/sql/validate-connection) command:
- ```mzsql
- VALIDATE CONNECTION ssh_connection;
- ```
- If no validation error is returned, move to the next step.
- 1. 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 another connection object, this time with database access and authentication details for Materialize to use:
- ```mzsql
- CREATE CONNECTION pg_connection TO POSTGRES (
- HOST '<host>',
- PORT 5432,
- USER 'materialize',
- PASSWORD SECRET pgpass,
- DATABASE '<database>',
- SSH TUNNEL ssh_connection
- );
- ```
- - 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;
- ```
- 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`.
|