ankane/pgsync is a data-focused project on GitHub with 3.5k stars, written primarily in Ruby. Sync data from one Postgres database to another
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Sync data from one Postgres database to another (like pg_dump/pg_restore). Designed for:
speed - tables are transferred in parallel
security - built-in methods to prevent sensitive data from ever leaving the server
flexibility - gracefully handles schema differences, like missing columns and extra columns
convenience - sync partial tables, groups of tables, and related records
:tangerine: Battle-tested at Instacart
Installation
pgsync is a command line tool. To install, run:
gem install pgsync
This will give you the pgsync command. If installation fails, you may need to install dependencies.
You can also install it with Homebrew:
brew install pgsync
Or Docker.
Setup
In your project directory, run:
pgsync --init
This creates .pgsync.yml for you to customize. We recommend checking this into your version control (assuming it doesn’t contain sensitive information). pgsync commands can be run from this directory or any subdirectory.
How to Use
First, make sure your schema is set up in both databases. We recommend using a schema migration tool for this, but pgsync also provides a few convenience methods. Once that’s done, you’re ready to sync data.
Sync tables
pgsync
Sync specific tables
pgsync table1,table2
Works with wildcards as well
pgsync "table*"
Sync specific rows (existing rows are overwritten)
pgsync products "where store_id = 1"
You can also preserve existing rows
pgsync products "where store_id = 1" --preserve
Or truncate them
pgsync products "where store_id = 1" --truncate
Tables
Exclude specific tables
pgsync --exclude table1,table2
Add to .pgsync.yml to exclude by default
exclude:
- table1
- table2
Sync tables from all schemas or specific schemas (by default, only the search path is synced)
pgsync --all-schemas
# or
pgsync --schemas public,other
# or
pgsync public.table1,other.table2
Groups
Define groups in .pgsync.yml:
groups:
group1:
- table1
- table2
And run:
pgsync group1
Variables
You can also use groups to sync a specific record and associated records in other tables.
To get product 123 with its reviews, last 10 coupons, and store, use:
groups:
product:
products: "where id = {1}"
reviews: "where product_id = {1}"
coupons: "where product_id = {1} order by created_at desc limit 10"
stores: "where id in (select store_id from products where id = {1})"
And run:
pgsync product:123
Schema
Sync the schema before the data (this wipes out existing data)
pgsync --schema-first
Specify tables
pgsync table1,table2 --schema-first
Sync the schema without data (this wipes out existing data)
pgsync --schema-only
pgsync does not try to sync Postgres extensions.
Sensitive Data
Prevent sensitive data like email addresses from leaving the remote server.
last_name matches all columns named last_name and users.last_name matches only the users table. Wildcards are supported, and the first matching rule is applied.
Options for replacement are:
unique_email
unique_phone
unique_secret
random_letter
random_int
random_date
random_time
random_ip
value
statement
null
untouched
Rules starting with unique_ require the table to have a single column primary key. unique_phone requires a numeric primary key.
Foreign Keys
Foreign keys can make it difficult to sync data. Three options are:
Defer constraints (recommended)
Manually specify the order of tables
Disable foreign key triggers, which can silently break referential integrity (not recommended)
To defer constraints, use:
pgsync --defer-constraints
To manually specify the order of tables, use --jobs 1 so tables are synced one-at-a-time.
pgsync table1,table2,table3 --jobs 1
To disable foreign key triggers and potentially break referential integrity, use:
pgsync --disable-integrity
This requires superuser privileges on the to database. If syncing to (not from) Amazon RDS, use the rds_superuser role. If syncing to (not from) Heroku, there doesn’t appear to be a way to disable integrity.
Triggers
Disable user triggers with:
pgsync --disable-user-triggers
Sequences
Skip syncing sequences with:
pgsync --no-sequences
Append-Only Tables
For extremely large, append-only tables, sync in batches.
pgsync large_table --in-batches
Note: This requires the table to have a numeric, increasing primary key
The script will resume where it left off when run again, making it great for backfills.
Connection Security
Always make sure your connection is secure when connecting to a database over a network you don’t fully trust. Your best option is to connect over SSH or a VPN. Another option is to use sslmode=verify-full. If you don’t do this, your database credentials can be compromised.
Safety
To keep you from accidentally overwriting production, the destination is limited to localhost or 127.0.0.1 by default.
To use another host, add to_safe: true to your .pgsync.yml.
Multiple Databases
To use with multiple databases, run:
pgsync --init db2
This creates .pgsync-db2.yml for you to edit. Specify a database in commands with:
pgsync --db db2
Integrations
Django
Heroku
Laravel
Rails
Django
If you run pgsync --init in a Django project, migrations will be excluded in .pgsync.yml.
exclude:
- django_migrations
Heroku
If you run pgsync --init in a Heroku project, the from database will be set in .pgsync.yml.
The most recent commit recorded on ankane/pgsync was 11 days ago, based on the GitHub push timestamp. The repository has 221 forks — one of the better signals of community interest.
How many stars does ankane/pgsync have?
ankane/pgsync has 3.5k GitHub stars — refresh the page for the live number, or check github.com/ankane/pgsync. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Data space?
ankane/pgsync is tracked by TopGit under the Data category, alongside 1 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is ankane/pgsync written in?
ankane/pgsync is written primarily in Ruby. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is ankane/pgsync associated with?
GitHub's repository topics for ankane/pgsync: "postgresql". TopGit's editorial category is Data.
Where do I read more about ankane/pgsync?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/ankane/pgsync is the definitive source.
Why is ankane/pgsync categorized under Data?
TopGit places ankane/pgsync in the Data category based on its GitHub topics and description (tagged: "postgresql"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Curious whether pgsync is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about pgsync.