-
Notifications
You must be signed in to change notification settings - Fork 2
Integrate/PostgreSQL: Add section with starter tutorial #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| (postgresql)= | ||
| # PostgreSQL | ||
|
|
||
| ```{div} .float-right | ||
| [{height=60px loading=lazy}][PostgreSQL] | ||
| ``` | ||
| ```{div} .clearfix | ||
| ``` | ||
|
|
||
| :::{rubric} About | ||
| ::: | ||
|
|
||
| [PostgreSQL] is the world's most advanced open source relational database. | ||
|
|
||
| :::{rubric} Synopsis | ||
| ::: | ||
|
|
||
| ```shell | ||
| uvx 'cratedb-toolkit[io-ingestr]' load table \ | ||
| "postgresql://postgres:postgres@localhost:5432/test?table=public.demo" \ | ||
| --cluster-url="crate://crate:crate@localhost:4200/doc/postgresql_demo" | ||
| ``` | ||
|
|
||
| :::{rubric} Learn | ||
| ::: | ||
|
|
||
| ::::{grid} | ||
|
|
||
| :::{grid-item-card} Tutorial: Use CrateDB Toolkit | ||
| :link: postgresql-tutorial | ||
| :link-type: ref | ||
| Load data from PostgreSQL into CrateDB using CrateDB Toolkit. | ||
| ::: | ||
|
|
||
| :::: | ||
|
|
||
|
|
||
| :::{toctree} | ||
| :maxdepth: 1 | ||
| :hidden: | ||
| Tutorial <tutorial> | ||
| ::: | ||
|
|
||
|
|
||
| [PostgreSQL]: https://www.postgresql.org/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| (postgresql-tutorial)= | ||
| # Load data from PostgreSQL into CrateDB | ||
|
|
||
| The tutorial will walk you through starting [PostgreSQL] and CrateDB, | ||
| inserting a record into PostgreSQL, loading data into a CrateDB table, | ||
| and validating that the data has been stored successfully. | ||
| The data transfer is supported by the | ||
| {ref}`CrateDB Toolkit Ingestr I/O <ctk:ingestr>` data pipeline elements. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| Docker is used for running all components. This approach works consistently | ||
| across Linux, macOS, and Windows. Alternatively, you can use Podman. | ||
|
|
||
| Create a shared network. | ||
| ```shell | ||
| docker network create cratedb-demo | ||
| ``` | ||
|
|
||
| Start CrateDB. | ||
| ```shell | ||
| docker run --rm --name=cratedb --network=cratedb-demo \ | ||
| --publish=4200:4200 --publish=5432:5432 --env=CRATE_HEAP_SIZE=2g \ | ||
| docker.io/crate -Cdiscovery.type=single-node | ||
| ``` | ||
amotl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Start PostgreSQL. | ||
| ```shell | ||
| docker run --rm --name=postgresql --network=cratedb-demo \ | ||
| --publish=6432:5432 --env "POSTGRES_HOST_AUTH_METHOD=trust" \ | ||
| docker.io/postgres postgres -c log_statement=all | ||
| ``` | ||
| :::{note} | ||
| Because CrateDB is configured to listen on port `5432` with its PostgreSQL | ||
| interface, let's use a different port for PostgreSQL itself. | ||
| ::: | ||
|
|
||
| Prepare shortcuts for the CrateDB shell, CrateDB Toolkit, and the PostgreSQL client | ||
| programs. | ||
|
|
||
| ::::{tab-set} | ||
|
|
||
| :::{tab-item} Linux and macOS | ||
| To make the settings persistent, add them to your shell profile (`~/.profile`). | ||
| ```shell | ||
| alias crash="docker run --rm -it --network=cratedb-demo ghcr.io/crate/cratedb-toolkit crash" | ||
| alias ctk-ingest="docker run --rm -i --network=cratedb-demo ghcr.io/crate/cratedb-toolkit-ingest ctk" | ||
| alias psql="docker run --rm -i --network=cratedb-demo docker.io/postgres psql" | ||
| ``` | ||
| ::: | ||
| :::{tab-item} Windows PowerShell | ||
| To make the settings persistent, add them to your PowerShell profile (`$PROFILE`). | ||
| ```powershell | ||
| function crash { docker run --rm -it --network=cratedb-demo ghcr.io/crate/cratedb-toolkit crash @args } | ||
| function ctk-ingest { docker run --rm -i --network=cratedb-demo ghcr.io/crate/cratedb-toolkit-ingest ctk @args } | ||
| function psql { docker run --rm -i --network=cratedb-demo docker.io/postgres psql @args } | ||
| ``` | ||
| ::: | ||
| :::{tab-item} Windows Command | ||
| ```shell | ||
| doskey crash=docker run --rm -it --network=cratedb-demo ghcr.io/crate/cratedb-toolkit crash $* | ||
| doskey ctk-ingest=docker run --rm -i --network=cratedb-demo ghcr.io/crate/cratedb-toolkit-ingest ctk $* | ||
| doskey psql=docker run --rm -i --network=cratedb-demo docker.io/postgres psql $* | ||
| ``` | ||
| ::: | ||
|
|
||
| :::: | ||
|
|
||
| ## Usage | ||
|
|
||
| Write a few sample records to PostgreSQL. | ||
| ```shell | ||
| psql "postgresql://postgres:postgres@postgresql:5432/" <<SQL | ||
| CREATE DATABASE test; | ||
| \connect test; | ||
| CREATE TABLE IF NOT EXISTS demo (id BIGINT, data JSONB); | ||
| INSERT INTO demo (id, data) VALUES (1, '{"temperature": 42.84, "humidity": 83.1}'); | ||
| INSERT INTO demo (id, data) VALUES (2, '{"temperature": 84.84, "humidity": 56.99}'); | ||
| SQL | ||
| ``` | ||
|
|
||
| Invoke the data transfer pipeline. | ||
| ```shell | ||
| ctk-ingest load table \ | ||
| "postgresql://postgres:postgres@postgresql:5432/test?table=public.demo" \ | ||
| --cluster-url="crate://crate:crate@cratedb:4200/doc/postgresql_demo" | ||
| ``` | ||
|
|
||
| Inspect data stored in CrateDB. | ||
| ```shell | ||
| crash --hosts cratedb -c "SELECT * FROM doc.postgresql_demo" | ||
| ``` | ||
|
|
||
|
|
||
| [PostgreSQL]: https://www.postgresql.org/ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.