Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Railway 3 min read How-to mediumAdept

How to Backup and Restore Your Postgres Database

Postgres databases on Railway can be backed up with pg_dump using tar format (-F t) and the PGUSER, PGHOST, PGPORT, PGDATABASE and PGPASSWORD values from the project's variables, then restored into another Railway Postgres instance with pg_restore. Install steps for the psql client cover macOS (Homebrew), Ubuntu (postgresql-client) and Windows (WSL2 or installer). For Heroku migrations, use a direct pg_dump instead of heroku pg:backups:download, since Heroku's dump format is specialized. Prisma users may see a harmless warning during restore.

Assumes: command line basicsPostgreSQL basics

Related posts

  • How we migrate TBs from Heroku without logical replication

    PlanetScale mediumAdept

    PlanetScale's open-source Heroku Migrator moves multi-terabyte Postgres databases off Heroku standard plans, which lack WAL access and logical replication, by using Bucardo trigger-based replication: triggers record changes in delta tables, a one-time COPY loads existing data, and a worker replays the backlog before a controlled switchover with verification. Version 2.0 fixes failures seen on large migrations. Bucardo's single-transaction initial copy restarted from zero after any interruption, so the migrator now drops secondary indexes before the copy and rebuilds them in parallel afterwards, raising throughput from about 60 to nearly 300 GB/h. It also disables transaction_timeout on Bucardo's connections, sets TCP keepalives so silently dropped long-lived connections fail within about a minute, and tunes host TCP buffers. A discovery CLI and the Liftoff assessment flag tables without primary keys, incompatible extensions and sizing before the migration starts.

  • Automated PostgreSQL Backups

    Railway mediumAdept

    A deployable Node.js template automates PostgreSQL backups on Railway by running a cron job that uploads compressed dumps to an S3 bucket. Setup involves creating an S3 bucket and an IAM user with programmatic access, ideally restricted to s3:PutObject on that bucket rather than AmazonS3FullAccess. The service is then configured through environment variables for AWS credentials, bucket, region, the BACKUP_DATABASE_URL and an optional cron schedule that defaults to daily at 5 AM UTC. Restoring means extracting the tar.gz and running pg_restore against the target database URL.

  • Security Disclosure Recommendation: Rotate PostgreSQL Database Credentials

    Railway mediumAdept

    After Railway's October 21, 2026 security disclosure, PostgreSQL users on the Railway template should regenerate the database password from the Database View, which changes it inside PostgreSQL and updates POSTGRES_PASSWORD and the variables that reference it in one step. Dependent services must then be redeployed because containers only read variables at startup, and pasted connection strings should be replaced with reference variables. Afterwards, verify with pg_stat_activity, terminate unknown sessions, disable public TCP proxy access if unneeded, and check audit logs, failed-auth logs, unexpected roles and modified data for misuse. Editing password variables or running ALTER USER by hand leaves the variable and the database out of sync, so avoid it.

  • Neon Twin: Automate Partial Data Dumps with Postgres and GitHub Actions

    Neon mediumAdept

    A scheduled GitHub Actions workflow can keep a Neon "Twin" refreshed with a partial copy of a production Postgres database. It installs a pinned Postgres version via apt, dumps the schema with pg_dump, extracts row subsets to CSV with psql \copy, then drops and recreates the target schema and restores it with pg_restore. When subsetting related tables, the selection queries must keep foreign keys intact and the restore must load parent tables first. Partial dumps can also reduce PII exposure by leaving out sensitive tables and columns.

  • How to Keep Staging in Sync with Production in Postgres

    Neon mediumAdept

    Postgres staging environments drift from production, and the traditional fixes each fall short. pg_dump/pg_restore gives a clean copy but takes staging offline and runs for hours on large databases. Logical replication and AWS DMS keep rows in sync but not schema or configuration, and they add load to production. All three copy PII as-is. Database branching with copy-on-write storage, as in Neon, makes staging an instantly resettable branch of production, and an intermediate anonymized branch masks sensitive columns before staging and dev branches are derived from it.

The quest for software engineering knowledge.

Look:
Layout: