0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · 강의

대기 서버 설정

지속적인 데이터 동기화를 위해 PostgreSQL 대기 서버를 초기화하고 구성하는 실무 단계를 따라가며 학습합니다.

대기 서버 설정은(는) CoddyKit의 무료 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Advanced PostgreSQL: Indexing, Partitioning, Replication 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Welcome to Standby Setup

In this lesson, we'll walk through the practical steps to set up a PostgreSQL standby server. This server will continuously synchronize data from your primary server, acting as a read-replica and a crucial part of your disaster recovery strategy.

We'll cover the necessary configurations on both the primary and the standby.

Primary Prep: Replication User

Before initializing our standby, we need a dedicated user on the primary server with replication privileges. This user will be used by the standby to connect and stream WAL (Write-Ahead Log) data.

Run this SQL command on your primary PostgreSQL server:

CREATE USER repluser REPLICATION LOGIN CONNECTION LIMIT 1 ENCRYPTED PASSWORD 'StrongPassword123!';

Primary Prep: Access Control

Next, we need to tell the primary server to accept connections from our standby server for replication. Edit the pg_hba.conf file on your primary server.

Add an entry like this, replacing 192.168.1.100 with the actual IP address of your standby server:

host    replication     repluser        192.168.1.100/32        md5

Primary Prep: Apply Changes

After modifying pg_hba.conf, PostgreSQL needs to reload its configuration. You can do this without a full restart in most cases.

Execute this command on your primary server:

sudo systemctl reload postgresql

Standby: Initial Data Copy

Now, let's move to the standby server. The first step is to get a base copy of the primary's data directory. We use pg_basebackup for this. This command connects to the primary, copies all its data, and creates necessary recovery configuration files.

Run this command on your standby server, replacing placeholders:

pg_basebackup -h primary_ip -U repluser -D /var/lib/postgresql/16/main -P -R

Decoding pg_basebackup Options

Let's break down the pg_basebackup options:

  • -h primary_ip: Hostname or IP of the primary server.
  • -U repluser: The replication user we created.
  • -D /path/to/data: The data directory on the standby.
  • -P: Show progress during the backup.
  • -R: Crucial! Creates a standby.signal file and appends primary_conninfo to postgresql.conf, configuring the standby for recovery.

Standby: Essential Configuration

The -R option handles most of the recovery setup. However, ensure hot_standby is enabled in the standby's postgresql.conf if you want to use it for read queries.

Open postgresql.conf on the standby and ensure this line is present and uncommented:

hot_standby = on

Standby: Connection String

The -R option should have automatically added a primary_conninfo entry to your standby's postgresql.conf. This tells the standby how to connect to the primary.

Verify it looks similar to this, with your actual primary IP and replication user password:

primary_conninfo = 'host=primary_ip port=5432 user=repluser password=StrongPassword123!'

Starting the Standby

With the data copied and configuration in place, you can now start the PostgreSQL service on your standby server. It will automatically begin connecting to the primary and streaming WAL records.

Execute this command on your standby server:

sudo systemctl start postgresql

Verify Replication Status

To confirm that replication is working, connect to your primary server and query the pg_stat_replication view. You should see an entry for your standby server.

A state of 'streaming' indicates success!

SELECT client_addr, state, sync_state FROM pg_stat_replication;

Check Your Setup

You've just set up a PostgreSQL standby! Let's test your understanding of a key step.

Standby Setup Summary

Great job! You've successfully configured a PostgreSQL standby server for streaming replication. This involves:

  • Creating a replication user on the primary.
  • Configuring pg_hba.conf on the primary.
  • Using pg_basebackup -R on the standby for initial data copy and automatic configuration.
  • Ensuring hot_standby = on on the standby.
  • Starting the standby and verifying its status.

Your standby is now ready to receive continuous updates from the primary!

자주 묻는 질문

“대기 서버 설정” 강의는 무료인가요?

네 — “대기 서버 설정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의 전체를 잠금 해제할 수 있습니다. Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 총 4개의 강의가 포함되어 있습니다.

“대기 서버 설정”에서 뭘 배우나요?

지속적인 데이터 동기화를 위해 PostgreSQL 대기 서버를 초기화하고 구성하는 실무 단계를 따라가며 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 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 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 복제 개념 이해
  2. 물리적 복제(스트리밍)
  3. 대기 서버 설정
  4. 동기식 복제와 비동기식 복제 비교
← Advanced PostgreSQL: Indexing, Partitioning, Replication(으)로 돌아가기