-
Notifications
You must be signed in to change notification settings - Fork 50
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
Postgres replication #392
Merged
Merged
Postgres replication #392
Changes from 27 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
cb58fbc
WIP
d218a3a
WIP
945da6d
Merge branch 'master' of https://github.com/dlt-hub/verified-sources …
fa9a4c1
move config to correct position
4cdf823
extend SQLAlchemy type mapping
8808812
add initial support for postgres replication
1914acf
add credentials instruction
36739ec
Merge branch 'master' of https://github.com/dlt-hub/verified-sources …
cc6a11d
undo adding secret
f815361
add module docstring
a318fee
use from import to prevent AttributeError when running test_dlt_init.py
8aed399
enable multiple tables per publication
9fc3c39
add support for schema replication
8c2f905
add support for unmapped data types
a0af605
add test for init_replication
051830c
update docstrings
656989a
return resource instead of single-element list
d014645
add example pipeline
269422e
add more example pipelines
c674f24
add nullability hints
a919c82
add README
57b5e1e
add sql_database dependency instruction
5636e07
batch data items per table and yield hints only once
2713464
postpone replication column hints to preserve order
eec75f0
refactor to use resource decorator
aae3754
Merge branch 'master' of https://github.com/dlt-hub/verified-sources …
493147d
add support for table schema changes
7bd211b
optimize message type detection for performance
48442ba
upgrade dlt to 0.4.8
d303efd
Merge branch 'master' of https://github.com/dlt-hub/verified-sources …
524945f
enables to run tests in parallel
rudolfix ab005a1
Merge branch 'master' into 933-postgres-replication
rudolfix c596180
fixes format
rudolfix 34610b6
make test more specific to handle postgres version differences
7a07045
add postgres server version requirement for schema replication functi…
61712b4
removed whitespace
fd1d973
explicitly fetch credentials from pg_replication source
8bc4da3
add superuser check
796c980
Merge branch 'master' into 933-postgres-replication
rudolfix 77fb1dd
updates lock file
rudolfix 8a1d910
use psycopg2-binary instead of psycopg2
b0d2abb
use destination-specific escape identifier
f63ceff
replace string literal with int literal
22758fe
include pypgoutput decoders in library
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,67 @@ | ||
# Postgres replication | ||
[Postgres](https://www.postgresql.org/) is one of the most popular relational database management systems. This verified source uses Postgres' replication functionality to efficiently process changes in tables (a process often referred to as _Change Data Capture_ or CDC). It uses [logical decoding](https://www.postgresql.org/docs/current/logicaldecoding.html) and the standard built-in `pgoutput` [output plugin](https://www.postgresql.org/docs/current/logicaldecoding-output-plugin.html). | ||
|
||
Resources that can be loaded using this verified source are: | ||
|
||
| Name | Description | | ||
|----------------------|-------------------------------------------------| | ||
| replication_resource | Load published messages from a replication slot | | ||
|
||
## Initialize the pipeline | ||
|
||
```bash | ||
dlt init pg_replication duckdb | ||
``` | ||
|
||
This uses `duckdb` as destination, but you can choose any of the supported [destinations](https://dlthub.com/docs/dlt-ecosystem/destinations/). | ||
|
||
## Add `sql_database` source | ||
|
||
```bash | ||
dlt init sql_database duckdb | ||
``` | ||
|
||
This source depends on the [sql_database](../sql_database/README.md) verified source internally to perform initial loads. This step can be skipped if you don't do initial loads. | ||
## Set up user | ||
|
||
The Postgres user needs to have the `LOGIN` and `REPLICATION` attributes assigned: | ||
|
||
```sql | ||
CREATE ROLE replication_user WITH LOGIN REPLICATION; | ||
``` | ||
|
||
It also needs `CREATE` privilege on the database: | ||
|
||
```sql | ||
GRANT CREATE ON DATABASE dlt_data TO replication_user; | ||
``` | ||
|
||
## Add credentials | ||
1. Open `.dlt/secrets.toml`. | ||
2. Enter your Postgres credentials: | ||
|
||
```toml | ||
[sources.pg_replication] | ||
credentials="postgresql://replication_user:<<password>>@localhost:5432/dlt_data" | ||
``` | ||
3. Enter credentials for your chosen destination as per the [docs](https://dlthub.com/docs/dlt-ecosystem/destinations/). | ||
|
||
## Run the pipeline | ||
|
||
1. Install the necessary dependencies by running the following command: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
``` | ||
|
||
1. Now the pipeline can be run by using the command: | ||
|
||
```bash | ||
python pg_replication_pipeline.py | ||
``` | ||
|
||
1. To make sure that everything is loaded as expected, use the command: | ||
|
||
```bash | ||
dlt pipeline pg_replication_pipeline show | ||
``` |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a good place to tell the user to use
dlt init sql_database ...
if they want to use this initial resourceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extended the README: 57b5e1e