Prerequisites
The following demo needs to be completed under twopsql connections. One connection links to PostgreSQL, providing the source data for analysis and obtaining the analysis results from RisingWave. In our demo, the command to connect to PostgreSQL is psql -h localhost -p 5432 -d myd -U postgresuser, with the password being postgrespw. The other connection links to RisingWave to establish a job for analyzing the data. In our demo, the command to connect to RisingWave is psql -h localhost -p 4566 -d dev -U root, with no password required. You can choose to exit from psql and log in to the other database when you need to operate in another database. Alternatively, you can use tmux to open two terminals simultaneously, connecting to the respective databases with psql.
- The PostgreSQL used supports the
postgres_fdwextension. - Both PostgreSQL and RisingWave are accessible from each other.
- Both of the users in PostgreSQL (
postgresuserin this demo) and in RisingWave (rootin this demo) have the necessary permissions to create tables and materialized views.
Prepare data in PostgreSQL
The following commands create a table in PostgreSQL and insert data into it.Analyze data in RisingWave
The following command creates a table in RisingWave. This table will use the native CDC connector to synchronize the data of the Person table from PostgreSQL, and then create a materialized view to analyze the ingested data.Query result in PostgreSQL using FDW
The following command creates a foreign table in PostgreSQL to connect to RisingWave and query the materialized view. The first four commands prepare the remote access ofpostgres_fdw. You can check the PostgreSQL’s doc here for more details.
Currently, write operations to RisingWave through a foreign data wrapper are not supported. The data in the foreign table is read-only.