Skip to content

Commit f680752

Browse files
committed
replicators: Add an option to skip CREATE PUBLICATION in postgres
Readyset contains a command line option for disabling setting up the DDL event triggers (--disable-setup-ddl-replication). This is useful when the database user is not a superuser and triggers are created manually. CREATE PUBLICATION also requires superuser privileges. This commit adds a new command line option, --disable-create-publication for skipping publication creation. If this option is passed, the publication has to be created manually before the replication starts. Release-Note-Core: New option --disable-create-publication for skipping creating a publication. Used when readyset is not running as a superuser and the publication has been created manually. Change-Id: If25d880f8730efd778c7d77d81c49ace428a0eea Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7705 Tested-by: Buildkite CI Reviewed-by: Vassili Zarouba <vassili@readyset.io> Reviewed-by: Jason Brown <jason.b@readyset.io>
1 parent 4127594 commit f680752

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

database-utils/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ pub struct UpstreamConfig {
6464
#[serde(default)]
6565
pub disable_setup_ddl_replication: bool,
6666

67+
/// Disable running CREATE PUBLICATION query for PostgreSQL. If this flag is set
68+
/// a publication named readyset should be adced for all tables manually on the
69+
/// primary server before streaming replication will start.
70+
#[arg(long, env = "DISABLE_CREATE_PUBLICATION", hide = true)]
71+
#[serde(default)]
72+
pub disable_create_publication: bool,
73+
6774
/// Server ID to use when registering as a replication follower with the upstream db
6875
///
6976
/// This can be used to differentiate different ReadySet deployments connected to the same
@@ -244,6 +251,7 @@ impl Default for UpstreamConfig {
244251
upstream_db_url: Default::default(),
245252
disable_upstream_ssl_verification: false,
246253
disable_setup_ddl_replication: false,
254+
disable_create_publication: false,
247255
replication_server_id: Default::default(),
248256
replicator_restart_timeout: Duration::from_secs(1),
249257
replication_tables: Default::default(),

replicators/src/postgres_connector/connector.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,18 @@ impl PostgresWalConnector {
167167
//
168168
// Note that later on, this means we'll need to make sure we resnapshot *all* tables!
169169
connector
170-
.create_publication_and_slot(repl_slot_name)
170+
.create_publication_and_slot(repl_slot_name, config)
171171
.await?;
172172
}
173173

174174
Ok(connector)
175175
}
176176

177-
async fn create_publication_and_slot(&mut self, repl_slot_name: &str) -> ReadySetResult<()> {
177+
async fn create_publication_and_slot(
178+
&mut self,
179+
repl_slot_name: &str,
180+
config: UpstreamConfig,
181+
) -> ReadySetResult<()> {
178182
let system = self.identify_system().await?;
179183
debug!(
180184
id = %system.id,
@@ -183,20 +187,22 @@ impl PostgresWalConnector {
183187
dbname = ?system.dbname
184188
);
185189

186-
match self.create_publication(PUBLICATION_NAME).await {
187-
Ok(()) => {
188-
// Created a new publication, everything is good
189-
}
190-
Err(err)
191-
if err.to_string().contains("publication")
192-
&& err.to_string().contains("already exists") =>
193-
{
194-
// This is an existing publication we are going to use
195-
}
196-
Err(err) if err.to_string().contains("permission denied") => {
197-
error!("Insufficient permissions to create publication FOR ALL TABLES");
190+
if !config.disable_create_publication {
191+
match self.create_publication(PUBLICATION_NAME).await {
192+
Ok(()) => {
193+
// Created a new publication, everything is good
194+
}
195+
Err(err)
196+
if err.to_string().contains("publication")
197+
&& err.to_string().contains("already exists") =>
198+
{
199+
// This is an existing publication we are going to use
200+
}
201+
Err(err) if err.to_string().contains("permission denied") => {
202+
error!("Insufficient permissions to create publication FOR ALL TABLES");
203+
}
204+
Err(err) => return Err(err),
198205
}
199-
Err(err) => return Err(err),
200206
}
201207

202208
// Drop the existing slot if any

0 commit comments

Comments
 (0)