[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7844":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},7844,"pgsync","ankane\u002Fpgsync","ankane","Sync data from one Postgres database to another","",null,"Ruby",3452,218,34,10,0,3,59.32,"MIT License",false,"master",[23],"postgresql","2026-06-12 04:00:36","# pgsync\n\nSync data from one Postgres database to another (like `pg_dump`\u002F`pg_restore`). Designed for:\n\n- **speed** - tables are transferred in parallel\n- **security** - built-in methods to prevent sensitive data from ever leaving the server\n- **flexibility** - gracefully handles schema differences, like missing columns and extra columns\n- **convenience** - sync partial tables, groups of tables, and related records\n\n:tangerine: Battle-tested at [Instacart](https:\u002F\u002Fwww.instacart.com\u002Fopensource)\n\n[![Build Status](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync\u002Factions\u002Fworkflows\u002Fbuild.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync\u002Factions)\n\n## Installation\n\npgsync is a command line tool. To install, run:\n\n```sh\ngem install pgsync\n```\n\nThis will give you the `pgsync` command. If installation fails, you may need to install [dependencies](#dependencies).\n\nYou can also install it with Homebrew:\n\n```sh\nbrew install pgsync\n```\n\nOr [Docker](#docker).\n\n## Setup\n\nIn your project directory, run:\n\n```sh\npgsync --init\n```\n\nThis 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.\n\n## How to Use\n\nFirst, 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](#schema). Once that’s done, you’re ready to sync data.\n\nSync tables\n\n```sh\npgsync\n```\n\nSync specific tables\n\n```sh\npgsync table1,table2\n```\n\nWorks with wildcards as well\n\n```sh\npgsync \"table*\"\n```\n\nSync specific rows (existing rows are overwritten)\n\n```sh\npgsync products \"where store_id = 1\"\n```\n\nYou can also preserve existing rows\n\n```sh\npgsync products \"where store_id = 1\" --preserve\n```\n\nOr truncate them\n\n```sh\npgsync products \"where store_id = 1\" --truncate\n```\n\n## Tables\n\nExclude specific tables\n\n```sh\npgsync --exclude table1,table2\n```\n\nAdd to `.pgsync.yml` to exclude by default\n\n```yml\nexclude:\n  - table1\n  - table2\n```\n\nSync tables from all schemas or specific schemas (by default, only the search path is synced)\n\n```sh\npgsync --all-schemas\n# or\npgsync --schemas public,other\n# or\npgsync public.table1,other.table2\n```\n\n## Groups\n\nDefine groups in `.pgsync.yml`:\n\n```yml\ngroups:\n  group1:\n    - table1\n    - table2\n```\n\nAnd run:\n\n```sh\npgsync group1\n```\n\n## Variables\n\nYou can also use groups to sync a specific record and associated records in other tables.\n\nTo get product `123` with its reviews, last 10 coupons, and store, use:\n\n```yml\ngroups:\n  product:\n    products: \"where id = {1}\"\n    reviews: \"where product_id = {1}\"\n    coupons: \"where product_id = {1} order by created_at desc limit 10\"\n    stores: \"where id in (select store_id from products where id = {1})\"\n```\n\nAnd run:\n\n```sh\npgsync product:123\n```\n\n## Schema\n\nSync the schema before the data (this wipes out existing data)\n\n```sh\npgsync --schema-first\n```\n\nSpecify tables\n\n```sh\npgsync table1,table2 --schema-first\n```\n\nSync the schema without data (this wipes out existing data)\n\n```sh\npgsync --schema-only\n```\n\npgsync does not try to sync Postgres extensions.\n\n## Sensitive Data\n\nPrevent sensitive data like email addresses from leaving the remote server.\n\nDefine rules in `.pgsync.yml`:\n\n```yml\ndata_rules:\n  email: unique_email\n  last_name: random_letter\n  birthday: random_date\n  users.auth_token:\n    value: secret\n  visits_count:\n    statement: \"(RANDOM() * 10)::int\"\n  encrypted_*: null\n```\n\n`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.\n\nOptions for replacement are:\n\n- `unique_email`\n- `unique_phone`\n- `unique_secret`\n- `random_letter`\n- `random_int`\n- `random_date`\n- `random_time`\n- `random_ip`\n- `value`\n- `statement`\n- `null`\n- `untouched`\n\nRules starting with `unique_` require the table to have a single column primary key. `unique_phone` requires a numeric primary key.\n\n## Foreign Keys\n\nForeign keys can make it difficult to sync data. Three options are:\n\n1. Defer constraints (recommended)\n2. Manually specify the order of tables\n3. Disable foreign key triggers, which can silently break referential integrity (not recommended)\n\nTo defer constraints, use:\n\n```sh\npgsync --defer-constraints\n```\n\nTo manually specify the order of tables, use `--jobs 1` so tables are synced one-at-a-time.\n\n```sh\npgsync table1,table2,table3 --jobs 1\n```\n\nTo disable foreign key triggers and potentially break referential integrity, use:\n\n```sh\npgsync --disable-integrity\n```\n\nThis 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.\n\n## Triggers\n\nDisable user triggers with:\n\n```sh\npgsync --disable-user-triggers\n```\n\n## Sequences\n\nSkip syncing sequences with:\n\n```sh\npgsync --no-sequences\n```\n\n## Append-Only Tables\n\nFor extremely large, append-only tables, sync in batches.\n\n```sh\npgsync large_table --in-batches\n```\n\nNote: This requires the table to have a numeric, increasing primary key\n\nThe script will resume where it left off when run again, making it great for backfills.\n\n## Connection Security\n\nAlways make sure your [connection is secure](https:\u002F\u002Fankane.org\u002Fpostgres-sslmode-explained) 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.\n\n## Safety\n\nTo keep you from accidentally overwriting production, the destination is limited to `localhost` or `127.0.0.1` by default.\n\nTo use another host, add `to_safe: true` to your `.pgsync.yml`.\n\n## Multiple Databases\n\nTo use with multiple databases, run:\n\n```sh\npgsync --init db2\n```\n\nThis creates `.pgsync-db2.yml` for you to edit. Specify a database in commands with:\n\n```sh\npgsync --db db2\n```\n\n## Integrations\n\n- [Django](#django)\n- [Heroku](#heroku)\n- [Laravel](#laravel)\n- [Rails](#rails)\n\n### Django\n\nIf you run `pgsync --init` in a Django project, migrations will be excluded in `.pgsync.yml`.\n\n```yml\nexclude:\n  - django_migrations\n```\n\n### Heroku\n\nIf you run `pgsync --init` in a Heroku project, the `from` database will be set in `.pgsync.yml`.\n\n```yml\nfrom: $(heroku config:get DATABASE_URL)?sslmode=require\n```\n\n### Laravel\n\nIf you run `pgsync --init` in a Laravel project, migrations will be excluded in `.pgsync.yml`.\n\n```yml\nexclude:\n  - migrations\n```\n\n### Rails\n\nIf you run `pgsync --init` in a Rails project, Active Record metadata and schema migrations will be excluded in `.pgsync.yml`.\n\n```yml\nexclude:\n  - ar_internal_metadata\n  - schema_migrations\n```\n\n## Debugging\n\nTo view the SQL that’s run, use:\n\n```sh\npgsync --debug\n```\n\n## Other Commands\n\nHelp\n\n```sh\npgsync --help\n```\n\nVersion\n\n```sh\npgsync --version\n```\n\nList tables\n\n```sh\npgsync --list\n```\n\n## Scripts\n\nUse groups when possible to take advantage of parallelism.\n\nFor Ruby scripts, you may need to do:\n\n```rb\nBundler.with_unbundled_env do\n  system \"pgsync ...\"\nend\n```\n\n## Docker\n\nGet the [Docker image](https:\u002F\u002Fhub.docker.com\u002Fr\u002Fankane\u002Fpgsync) with:\n\n```sh\ndocker pull ankane\u002Fpgsync\nalias pgsync=\"docker run -ti --rm -v .:\u002Fconf -w \u002Fconf ankane\u002Fpgsync\"\n```\n\nThis will give you the `pgsync` command.\n\nFor databases on the host machine, use `host.docker.internal` as the hostname (on Linux, this requires `--add-host=host.docker.internal:host-gateway`).\n\n## Dependencies\n\nIf installation fails, your system may be missing Ruby or libpq.\n\nOn Mac, run:\n\n```sh\nbrew install libpq\n```\n\nOn Ubuntu, run:\n\n```sh\nsudo apt-get install ruby-dev libpq-dev build-essential\n```\n\n## Upgrading\n\nRun:\n\n```sh\ngem install pgsync\n```\n\nTo use master, run:\n\n```sh\ngem install specific_install\ngem specific_install https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync.git\n```\n\nWith Homebrew, run:\n\n```sh\nbrew upgrade pgsync\n```\n\nWith Docker, run:\n\n```sh\ndocker pull ankane\u002Fpgsync\n```\n\n## Related Projects\n\nAlso check out:\n\n- [Dexter](https:\u002F\u002Fgithub.com\u002Fankane\u002Fdexter) - The automatic indexer for Postgres\n- [PgHero](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpghero) - A performance dashboard for Postgres\n- [pgslice](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgslice) - Postgres partitioning as easy as pie\n\n## Thanks\n\nInspired by [heroku-pg-transfer](https:\u002F\u002Fgithub.com\u002Fddollar\u002Fheroku-pg-transfer).\n\n## History\n\nView the [changelog](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync\u002Fblob\u002Fmaster\u002FCHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync\u002Fissues)\n- Fix bugs and [submit pull requests](https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync\u002Fpulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002Fankane\u002Fpgsync.git\ncd pgsync\nbundle install\n\ncreatedb pgsync_test1\ncreatedb pgsync_test2\ncreatedb pgsync_test3\n\nbundle exec rake test\n```\n","pgsync 是一个用于将数据从一个 PostgreSQL 数据库同步到另一个数据库的工具。它支持并行传输表以提高速度，内置方法确保敏感数据不会离开服务器，能够灵活处理不同模式之间的差异（如缺少或额外的列），并且提供了方便的部分表、表组以及相关记录同步的功能。适用于需要快速安全地迁移或复制数据库场景，尤其是在开发、测试或是生产环境之间同步数据时非常有用。安装简单，通过 Ruby gem 或 Homebrew 即可获得，并且配置文件易于定制和管理。",2,"2026-06-11 03:14:41","top_language"]