Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/pgsync/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def slop_options
o.boolean "--defer-constraints-v2", "defer constraints", default: false
o.boolean "--disable-integrity", "disable foreign key triggers", default: false
o.integer "-j", "--jobs", "number of tables to sync at a time"
o.integer "--throttle-bytes-per-second", "limit the sync to roughly this many bytes per second"

# replaced by v2
o.boolean "--defer-constraints", "defer constraints", default: false, help: false
Expand Down
6 changes: 6 additions & 0 deletions lib/pgsync/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,17 @@ def copy(source_command, dest_table:, dest_fields:)

source.log_sql(source_command)
destination.log_sql(destination_command)
bytes_count = 0
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

destination.conn.copy_data(destination_command) do
source.conn.copy_data(source_command) do
while (row = source.conn.get_copy_data)
while opts[:throttle_bytes_per_second] && (bytes_count / (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time)) > opts[:throttle_bytes_per_second]
sleep(0.01)
end
destination.conn.put_copy_data(row)
bytes_count += row.bytesize
end
end
end
Expand Down