Skip to content

Commit 2a9105d

Browse files
DOCSP-34351 PostGres Migration Prep Docs (#87)
* DOCSP-34351 PostGres Migration Prep Docs --------- Co-authored-by: jocelyn-mendez1 <[email protected]>
1 parent bc653d1 commit 2a9105d

File tree

1 file changed

+146
-1
lines changed

1 file changed

+146
-1
lines changed

source/prerequisites/postgres.txt

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,149 @@ Configure Migration Prerequisites for PostgreSQL
1010
:depth: 1
1111
:class: singlecol
1212

13-
Postgres.
13+
To run sync jobs from an PostgreSQL source database, the database may
14+
require some configuration changes. If Relational Migrator determines the
15+
database needs configuration changes, it automatically generates a
16+
SQL script with the required changes. It is recommended to have a
17+
Database Administrator (DBA) review the commands in this script and
18+
perform their execution on the database server. These instructions
19+
configuration PostgreSQL for both types of sync jobs:
20+
21+
.. include:: /includes/fact-short-sync-job-desc.rst
22+
23+
Before you Begin
24+
----------------
25+
26+
If PostgreSQL is configured as a cluster, Relational Migrator must
27+
connect to the master server.
28+
29+
Steps
30+
-----
31+
32+
.. tabs::
33+
34+
.. tab:: Snapshot Jobs
35+
:tabid: enable-snapshot-jobs
36+
37+
For snapshot jobs against PostgreSQL, the service account requires
38+
schema ``USAGE`` and table ``SELECT`` permissions.
39+
40+
.. code-block:: sql
41+
:copyable: true
42+
43+
GRANT USAGE ON SCHEMA <schema_name> TO <database_user_name>;
44+
GRANT SELECT ON TABLE <schema_name>.<table_name> TO <database_user_name>;
45+
46+
.. tab:: Continuous Jobs
47+
:tabid: enable-continuous-jobs
48+
49+
.. procedure::
50+
:style: normal
51+
52+
For continuous jobs against PostgreSQL, you must enable
53+
logical replication, grant role permissions to the service
54+
account, and create a publication.
55+
56+
.. step:: Enable logical replication
57+
58+
Logical replication may not be enabled by default. To enable logical
59+
replication, change the `wal_level <https://postgresqlco.nf/doc/en/param/wal_level>`__
60+
configuration in the
61+
`postgresql.conf configuration file <https://www.postgresql.org/docs/current/config-setting.html>`__.
62+
You *must restart the database instance* after changing the configuration file.
63+
64+
.. code-block:: none
65+
66+
wal_level = logical
67+
68+
If you are using PostgreSQL hosted on AWS RDS, you must
69+
set the ``rds.logical_replication`` parameter to ``1``.
70+
For details, see `Enable Logical Replication on AWS
71+
<https://repost.aws/knowledge-center/rds-postgresql-use-logical-replication>`__.
72+
You *must restart the database instance* after setting the
73+
parameter.
74+
75+
.. tip::
76+
77+
You can use the following query to check if your
78+
AWS RDS instance has logical
79+
replication enabled:
80+
81+
.. code-block:: sql
82+
:copyable: true
83+
84+
SELECT name,setting
85+
FROM pg_settings
86+
WHERE name IN ('wal_level','rds.logical_replication');
87+
88+
.. step:: Create a SQL replication role
89+
90+
a. Create a role with ``REPLICATION`` and ``LOGIN``
91+
database permissions:
92+
93+
.. code-block:: sql
94+
95+
CREATE ROLE <role> REPLICATION LOGIN;
96+
97+
#. Grant the table ``SELECT`` and schema ``USAGE``
98+
permissions to the role. Each table in
99+
the migration requires a ``GRANT SELECT`` statement:
100+
101+
.. code-block:: sql
102+
:copyable: true
103+
104+
GRANT USAGE ON SCHEMA <schema> TO <role>;
105+
GRANT SELECT ON <schema>.<table> TO <role>;
106+
-- ADDITIONAL GRANT SELECT STATEMENTS...
107+
108+
#. Grant the role to the service account
109+
110+
Replace ``<original_owner>`` with the owner of the
111+
participating tables.
112+
113+
.. code-block:: sql
114+
:copyable: true
115+
116+
GRANT <role> TO <original_owner>;
117+
GRANT <role> TO <database_user_name>;
118+
119+
.. step:: Grant ownership of each table to the role
120+
121+
Each table in the migration requires a ``ALTER TABLE``
122+
statement:
123+
124+
.. code-block:: sql
125+
:copyable: true
126+
127+
ALTER TABLE <schema>.<table> OWNER TO <role>;
128+
-- ADDITIONAL ALTER TABLE STATEMENTS...
129+
130+
.. step:: Create a publication
131+
132+
Create a `publication <https://www.postgresql.org/docs/current/logical-replication-publication.html>`__
133+
each table in the migration must be specified
134+
in the ``FOR`` statement separated by commas:
135+
136+
.. code-block:: sql
137+
:copyable: true
138+
139+
CREATE PUBLICATION "MIGRATOR_<name>_PUBLICATION"
140+
FOR TABLE "<schema>"."<table1>","<schema>"."<table2>";
141+
142+
.. step:: Set replica identity to full
143+
144+
Each table in the migration requires a ``ALTER TABLE``
145+
statement:
146+
147+
.. code-block:: sql
148+
:copyable: true
149+
150+
ALTER TABLE <schema>.<table> REPLICA IDENTITY FULL;
151+
-- ADDITIONAL ALTER TABLE STATEMENTS...
152+
153+
Learn More
154+
----------
155+
156+
Relational Migrator relies on the open-source Debezium connector to
157+
capture row-level changes. For more details, see
158+
`Debezium PostgreSQL <https://debezium.io/documentation/reference/stable/connectors/postgresql.html>`__.

0 commit comments

Comments
 (0)