Skip to content

Commit b54cd3c

Browse files
committed
fix(replication): Skip CREATE TABLESPACE statements on managed targets
SerenDB and some other managed PostgreSQL services do not support custom tablespaces. When replicating from a source that has tablespaces defined (like AWS RDS), the CREATE TABLESPACE statements now get commented out during globals restore. Fixes "CREATE TABLESPACE is not supported on SerenDB" errors.
1 parent 5d7c333 commit b54cd3c

6 files changed

Lines changed: 44 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [5.3.7] - 2025-12-02
6+
7+
### Fixed
8+
9+
- **Skip CREATE TABLESPACE statements during globals restore**: `CREATE TABLESPACE` statements are now automatically commented out when restoring to managed PostgreSQL targets like SerenDB that do not support custom tablespaces.
10+
511
## [5.3.6] - 2025-12-02
612

713
### Fixed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "database-replicator"
3-
version = "5.3.6"
3+
version = "5.3.7"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "Universal database-to-PostgreSQL replication CLI. Supports PostgreSQL, SQLite, MongoDB, and MySQL."

src/commands/init.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ pub async fn init(
232232
.context("Failed to remove restricted parameter settings from globals dump")?;
233233
remove_restricted_role_grants(globals_file.to_str().unwrap())
234234
.context("Failed to remove restricted role grants from globals dump")?;
235+
migration::remove_tablespace_statements(globals_file.to_str().unwrap())
236+
.context("Failed to remove CREATE TABLESPACE statements from globals dump")?;
235237

236238
// Step 2: Restore global objects
237239
tracing::info!("Step 2/4: Restoring global objects to target...");

src/migration/dump.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,39 @@ pub fn remove_restricted_guc_settings(path: &str) -> Result<()> {
168168
Ok(())
169169
}
170170

171+
/// Comments out `CREATE TABLESPACE` statements in a globals dump file.
172+
///
173+
/// Some managed PostgreSQL targets (e.g., SerenDB) do not support custom tablespaces.
174+
/// When replicating from a source that has tablespaces defined, this function
175+
/// comments out those statements to allow the globals restore to proceed.
176+
pub fn remove_tablespace_statements(path: &str) -> Result<()> {
177+
let content = fs::read_to_string(path)
178+
.with_context(|| format!("Failed to read globals dump at {}", path))?;
179+
180+
let mut updated = String::with_capacity(content.len());
181+
let mut modified = false;
182+
183+
for line in content.lines() {
184+
let lower_trimmed = line.trim().to_ascii_lowercase();
185+
if lower_trimmed.starts_with("create tablespace") {
186+
updated.push_str("-- ");
187+
updated.push_str(line);
188+
updated.push('\n');
189+
modified = true;
190+
} else {
191+
updated.push_str(line);
192+
updated.push('\n');
193+
}
194+
}
195+
196+
if modified {
197+
fs::write(path, updated)
198+
.with_context(|| format!("Failed to write sanitized globals dump to {}", path))?;
199+
}
200+
201+
Ok(())
202+
}
203+
171204
/// Comments out `GRANT` statements for roles that are restricted on managed services.
172205
///
173206
/// AWS RDS and other managed services may prevent granting certain default roles

src/migration/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod schema;
1111
pub use checksum::{compare_tables, compute_table_checksum, ChecksumResult};
1212
pub use dump::{
1313
dump_data, dump_globals, dump_schema, remove_restricted_guc_settings,
14-
remove_superuser_from_globals, sanitize_globals_dump,
14+
remove_superuser_from_globals, remove_tablespace_statements, sanitize_globals_dump,
1515
};
1616
pub use estimation::{estimate_database_sizes, format_bytes, format_duration, DatabaseSizeInfo};
1717
pub use filtered::copy_filtered_tables;

0 commit comments

Comments
 (0)