movePrimaryIn a sharded cluster,
movePrimaryreassigns the primary shard which holds all un-sharded collections in the database.movePrimaryfirst changes the primary shard in the cluster metadata, and then migrates all un-sharded collections to the specified shard. Use the command with the following form:db.adminCommand( { movePrimary: <databaseName>, to: <newPrimaryShard> } ) 예를 들어, 다음 명령은 프라이머리 샤드를
test에서shard0001로 이동합니다.db.adminCommand( { movePrimary : "test", to : "shard0001" } ) 명령이 반환되면 데이터베이스의 프라이머리 샤드 위치가 지정된 샤드로 전환됩니다. 샤드를 완전히 서비스 해제하려면
removeShard명령을 사용합니다.movePrimaryis an administrative command that is only available formongosinstances.경고
After starting
movePrimary, do not perform any read or write operations against any unsharded collection in that database until the command completes. Read or write operations issued against those collections during the migration can result in unexpected behavior, including potential failure of the migration operation or loss of data.
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
고려 사항
mongos uses "majority" write concern for movePrimary.
샤딩되지 않은 컬렉션
Only run movePrimary after you move unsharded collections using sh.moveCollection(). Starting in MongoDB 8.0, unmoved, unsharded collections are not available during the movePrimary process.
MongoDB 검색 인덱스
이동 중인 데이터베이스에 MongoDB Search를 사용하는 샤딩되지 않은 컬렉션이 포함되어 있는 경우, movePrimary가 완료된 후에 해당 컬렉션의 검색 인덱스를 사용할 수 없게 됩니다. movePrimary은(는) 이동하는 샤딩되지 않은 컬렉션의 UUID를 업데이트하기 때문에, 해당 컬렉션에 대해 MongoDB Search 인덱스를 수동으로 다시 빌드해야 합니다.
유지 관리 창
movePrimary may require a significant time to complete depending on the size of the database and factors such as network health or machine resources. During migration, attempts to write or perform any DDL operations to the unsharded collections on the database being moved fail with the error: "movePrimary is in progress".
Consider scheduling a maintenance window during which applications stop all reads and writes to the cluster. Issuing movePrimary during planned downtime mitigates the risk of encountering undefined behavior due to interleaving reads or writes to the unsharded collections in the database.
네임스페이스 충돌
movePrimary 대상 샤드에 충돌하는 컬렉션 네임스페이스가 포함된 경우 실패합니다. 예를 들면 다음과 같습니다.
관리자가
movePrimary를 발행하여hr데이터베이스의 프라이머리 샤드를 변경합니다.movePrimary가 해당 collection을 이동하는 동안 사용자 또는 애플리케이션이hr의 샤딩되지 않은 collection에 대해 쓰기 작업을 실행합니다. 쓰기 작업은 원래 프라이머리 샤드에 collection을 생성합니다.나중에 관리자가
movePrimary를 실행하여hr데이터베이스의 원래 프라이머리 샤드를 복원합니다.movePrimary인터리빙 쓰기 작업에서 남겨진 충돌 네임스페이스로 인해 실패합니다.
인덱스 재구축
movePrimary 작업의 일부로 대상 샤드는 프라이머리 샤드가 된 후 마이그레이션된 collection의 인덱스를 다시 작성해야 합니다. collection당 인덱스 수와 인덱싱할 데이터의 양에 따라 상당한 시간이 걸릴 수 있습니다.
인덱스 빌드 프로세스에 대한 자세한 내용 은 채워진 collection 에 대한 인덱스 빌드를 참조하세요.
변경 스트림
MongoDB 부터 8.0 는movePrimary 변경 스트림이 있는 이벤트 컬렉션을 무효화하지 않습니다. 컬렉션이 새 샤드 로 이동한 후에도 변경 스트림은 컬렉션에서 이벤트를 계속 읽을 수 있습니다.
이전 MongoDB 버전에서는 movePrimary 이(가) 컬렉션 변경 스트림을 무효화하므로 변경 스트림이 컬렉션에서 이벤트를 읽을 수 없습니다.
모든 MongoDB 버전에서 movePrimary 은 이동된 샤딩되지 않은 컬렉션의 UUID 를 업데이트합니다.
추가 정보
전체 절차 는 샤드 클러스터에서 샤드 제거를 참조하세요.