구독 관리
퍼블리케이션의 변경 사항을 수신하고 적용하도록 대기 서버에서 구독을 설정하고 관리합니다.
구독 관리은(는) CoddyKit의 무료 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Advanced PostgreSQL: Indexing, Partitioning, Replication 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
What is a Logical Subscription?
In PostgreSQL's logical replication, a subscription is the receiving end. It's configured on a subscriber server to connect to a publisher server and pull data changes from a specific publication.
Think of it as subscribing to a newspaper. The publisher creates the newspaper (publication), and you (the subscriber) sign up to receive it.
The Subscriber Server Role
The server where you create a subscription becomes the subscriber. This server will connect to the publisher, receive the changes (inserts, updates, deletes, truncates), and apply them to its local tables.
It's crucial that the tables on the subscriber have the same structure as the published tables on the master for replication to work correctly.
Creating a New Subscription
To start receiving data, you use the CREATE SUBSCRIPTION command. You need to specify the connection details to the publisher and the name of the publication you want to subscribe to.
This command is run on the subscriber database.
CREATE SUBSCRIPTION my_app_sub
CONNECTION 'dbname=source_db host=192.168.0.10 user=repl_user password=securepass'
PUBLICATION app_data_pub;Essential Subscription Options
When creating a subscription, several options control its behavior:
COPY_DATA: Iftrue(default), existing data from the published tables is copied.ENABLED: Iftrue(default), replication starts immediately.CREATE_SLOT: Iftrue(default), a replication slot is created on the publisher.SLOT_NAME: You can specify an existing slot name instead of creating a new one.
Full Subscription Example
Let's create a subscription named sales_replica. It connects to a publisher at 10.0.0.5, user repl_admin, for the publication sales_publication.
We explicitly ask to copy existing data and enable it right away.
-- Execute this on the subscriber database
CREATE SUBSCRIPTION sales_replica
CONNECTION 'dbname=sales_db host=10.0.0.5 user=repl_admin password=mysecret'
PUBLICATION sales_publication
WITH (copy_data = true, create_slot = true, enabled = true);Monitoring Subscription Status
After creating a subscription, you'll want to ensure it's running correctly. PostgreSQL provides the pg_stat_subscription view for this.
It shows details like connection info, enabled status, and the current state of replication.
-- On the subscriber server
SELECT
subname,
subenabled,
substate,
subslotname,
subconninfo
FROM pg_stat_subscription;Enabling and Disabling Subscriptions
You might need to temporarily pause replication, for example, during maintenance or schema changes. You can enable or disable a subscription using ALTER SUBSCRIPTION.
DISABLE: Stops the replication process.ENABLE: Resumes the replication process.
-- Temporarily stop replication for 'sales_replica'
ALTER SUBSCRIPTION sales_replica DISABLE;
-- Resume replication
ALTER SUBSCRIPTION sales_replica ENABLE;Refreshing Publication List
If the publisher adds new tables to a publication, the subscriber won't automatically start replicating them. You need to tell the subscriber to refresh its understanding of the publication.
The REFRESH PUBLICATION command updates the subscription's table list.
-- Update 'sales_replica' to include any newly added tables
ALTER SUBSCRIPTION sales_replica REFRESH PUBLICATION;Dropping a Subscription
When a subscription is no longer needed, you can drop it. This command is executed on the subscriber server. By default, it also attempts to drop the associated replication slot on the publisher.
Ensure the subscription is disabled before dropping it to prevent errors.
-- First, disable the subscription if it's enabled
ALTER SUBSCRIPTION sales_replica DISABLE;
-- Then, drop the subscription
DROP SUBSCRIPTION sales_replica;Subscription Management Check
You have a subscription named user_data_sub that is actively replicating data. You need to perform some schema changes on the subscriber and want to temporarily stop the data flow without removing the subscription entirely.
Recap: Managing Subscriptions
In this lesson, you learned how to manage subscriptions in PostgreSQL logical replication. You can create new subscriptions, monitor their status, enable/disable them for maintenance, refresh their publication list, and finally drop them when no longer needed.
Mastering these commands is key to maintaining a robust and flexible logical replication setup.
자주 묻는 질문
“구독 관리” 강의는 무료인가요?
네 — “구독 관리” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의 전체를 잠금 해제할 수 있습니다. Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 총 4개의 강의가 포함되어 있습니다.
“구독 관리”에서 뭘 배우나요?
퍼블리케이션의 변경 사항을 수신하고 적용하도록 대기 서버에서 구독을 설정하고 관리합니다. 브라우저에서 직접 실행하는 실습 코드로 Advanced PostgreSQL: Indexing, Partitioning, Replication을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Advanced PostgreSQL: Indexing, Partitioning, Replication을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Advanced PostgreSQL: Indexing, Partitioning, Replication은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“구독 관리” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.