use-ssh-tunnel.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 1. In the SQL client connected to Materialize, use the [`CREATE CONNECTION`](/sql/create-connection/#ssh-tunnel) command to create an SSH tunnel connection:
  2. ```mzsql
  3. CREATE CONNECTION ssh_connection TO SSH TUNNEL (
  4. HOST '<SSH_BASTION_HOST>',
  5. PORT <SSH_BASTION_PORT>,
  6. USER '<SSH_BASTION_USER>'
  7. );
  8. ```
  9. - 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).
  10. - Replace `<SSH_BASTION_USER>` with the username for the key pair you created for your SSH bastion host.
  11. 1. Get Materialize's public keys for the SSH tunnel connection:
  12. ```mzsql
  13. SELECT * FROM mz_ssh_tunnel_connections;
  14. ```
  15. 1. Log in to your SSH bastion host and add Materialize's public keys to the `authorized_keys` file, for example:
  16. ```sh
  17. # Command for Linux
  18. echo "ssh-ed25519 AAAA...76RH materialize" >> ~/.ssh/authorized_keys
  19. echo "ssh-ed25519 AAAA...hLYV materialize" >> ~/.ssh/authorized_keys
  20. ```
  21. 1. Back in the SQL client connected to Materialize, validate the SSH tunnel connection you created using the [`VALIDATE CONNECTION`](/sql/validate-connection) command:
  22. ```mzsql
  23. VALIDATE CONNECTION ssh_connection;
  24. ```
  25. If no validation error is returned, move to the next step.
  26. 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):
  27. ```mzsql
  28. CREATE SECRET pgpass AS '<PASSWORD>';
  29. ```
  30. 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:
  31. ```mzsql
  32. CREATE CONNECTION pg_connection TO POSTGRES (
  33. HOST '<host>',
  34. PORT 5432,
  35. USER 'materialize',
  36. PASSWORD SECRET pgpass,
  37. DATABASE '<database>',
  38. SSH TUNNEL ssh_connection
  39. );
  40. ```
  41. - Replace `<host>` with your PostgreSQL endpoint.
  42. - Replace `<database>` with the name of the database containing the tables you want to replicate to Materialize.
  43. 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):
  44. ```mzsql
  45. CREATE SOURCE mz_source
  46. IN CLUSTER ingest_postgres
  47. FROM POSTGRES CONNECTION pg_connection (PUBLICATION 'mz_source')
  48. FOR ALL TABLES;
  49. ```
  50. 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`.