Skip to content

Configuration

pgbranch stores its configuration in .pgbranch/config.json within your project directory.

your-project/
├── .pgbranch/
│ ├── config.json # Main configuration
│ ├── branches/ # Branch metadata
│ │ ├── main.json
│ │ └── feature.json
│ └── key # Local encryption key (deprecated)
├── src/
└── ...
{
"database": "string",
"host": "string",
"port": "number",
"user": "string",
"password": "string",
"remotes": {
"<name>": {
"name": "string",
"type": "string",
"url": "string",
"options": {}
}
},
"defaultRemote": "string"
}
FieldTypeRequiredDefaultDescription
databasestringYes-PostgreSQL database name
hoststringNolocalhostPostgreSQL host
portnumberNo5432PostgreSQL port
userstringNopostgresPostgreSQL user
passwordstringNo""PostgreSQL password
FieldTypeRequiredDescription
remotesobjectNoMap of remote configurations
defaultRemotestringNoName of default remote

Each remote in the remotes object:

FieldTypeRequiredDescription
namestringYesRemote identifier
typestringYesBackend type (s3, filesystem, r2)
urlstringYesRemote URL
optionsobjectNoBackend-specific options
{
"database": "myapp_dev",
"host": "localhost",
"port": 5432,
"user": "postgres"
}
{
"database": "myapp_dev",
"host": "localhost",
"port": 5432,
"user": "postgres",
"remotes": {
"origin": {
"name": "origin",
"type": "s3",
"url": "s3://my-bucket/pgbranch",
"options": {
"region": "us-east-1",
"accessKeyId": "ENC:v1:...",
"secretAccessKey": "ENC:v1:..."
}
}
},
"defaultRemote": "origin"
}
{
"database": "myapp_dev",
"host": "localhost",
"port": 5432,
"user": "postgres",
"remotes": {
"team": {
"name": "team",
"type": "s3",
"url": "s3://team-bucket/pgbranch",
"options": {
"region": "us-east-1",
"accessKeyId": "ENC:v1:...",
"secretAccessKey": "ENC:v1:..."
}
},
"backup": {
"name": "backup",
"type": "filesystem",
"url": "/mnt/backup/pgbranch"
},
"r2": {
"name": "r2",
"type": "r2",
"url": "r2://account123/pgbranch-bucket/snapshots",
"options": {
"accessKeyId": "ENC:v1:...",
"secretAccessKey": "ENC:v1:..."
}
}
},
"defaultRemote": "team"
}
{
"database": "myapp_dev",
"host": "localhost",
"port": 5432,
"user": "postgres",
"remotes": {
"minio": {
"name": "minio",
"type": "s3",
"url": "s3://pgbranch-bucket/snapshots",
"options": {
"endpoint": "http://minio.local:9000",
"accessKeyId": "ENC:v1:...",
"secretAccessKey": "ENC:v1:...",
"forcePathStyle": true
}
}
},
"defaultRemote": "minio"
}
OptionTypeRequiredDescription
regionstringYes*AWS region
accessKeyIdstringYes*AWS access key (encrypted)
secretAccessKeystringYes*AWS secret key (encrypted)
endpointstringNoCustom S3 endpoint (for MinIO)
forcePathStylebooleanNoUse path-style URLs

*Can be provided via environment variables instead

OptionTypeRequiredDescription
accessKeyIdstringYesR2 access key (encrypted)
secretAccessKeystringYesR2 secret key (encrypted)

No options required for filesystem remotes.

Branch files in .pgbranch/branches/:

{
"name": "feature-auth",
"created": "2024-01-15T14:22:00Z",
"parent": "main",
"snapshot": "pgbranch_feature_auth_abc123",
"lastAccessed": "2024-01-16T10:30:00Z"
}

pgbranch respects standard PostgreSQL and AWS environment variables:

VariableDescription
PGHOSTPostgreSQL host
PGPORTPostgreSQL port
PGUSERPostgreSQL user
PGPASSWORDPostgreSQL password
PGDATABASEPostgreSQL database
VariableDescription
AWS_ACCESS_KEY_IDAWS access key
AWS_SECRET_ACCESS_KEYAWS secret key
AWS_REGIONAWS region
AWS_ENDPOINT_URLCustom S3 endpoint

Environment variables take precedence over config file values.

  • .pgbranch/config.json (if using encrypted credentials or no passwords)
  • .pgbranch/branches/*.json
  • .pgbranch/config.json if it contains plaintext database passwords
  • ~/.pgbranch_key (user-level encryption key)
.pgbranch/config.json
# Only if config contains plaintext passwords

While you can edit config.json manually, it’s recommended to use commands:

Terminal window
# Database settings
pgbranch init -d newdb -H newhost
# Remotes
pgbranch remote add name url
pgbranch remote remove name
pgbranch remote set-default name

pgbranch validates config on every command. Common validation errors:

Error: database name is required
Error: invalid remote URL format
Error: remote 'origin' not found

If you need to update configuration format:

Terminal window
# Backup current config
cp .pgbranch/config.json .pgbranch/config.json.bak
# Reinitialize (preserves branches)
pgbranch init -d myapp_dev
# Re-add remotes
pgbranch remote add origin s3://bucket/prefix