Peers

Database peers represent PostgreSQL instances that can act as sources or destinations for replication mirrors. Before creating a mirror, you must configure both source and destination peers.

List Peers

Retrieve all configured database peers.

Endpoint

GET /v1/peers

Permission: authed (any authenticated user)

Response

Returns an array of peer objects with connection details.

Example

curl http://localhost:8112/v1/peers \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Passwords are never returned in API responses for security reasons.

Create Peer

Add a new database peer configuration.

Endpoint

POST /v1/peers

Permission: adminOnly

Request Body

FieldTypeRequiredDescription
namestringYesUnique identifier for this peer
hoststringYesDatabase hostname or IP address
portnumberYesPostgreSQL port (typically 5432)
userstringYesDatabase username
passwordstringYesDatabase password
databasestringYesDatabase name
ssl_modestringNoSSL mode: disable, require, verify-ca, verify-full, or prefer (default: prefer)

Response

Returns the created peer object (without password).

Example

curl -X POST http://localhost:8112/v1/peers \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "production-db",
    "host": "prod-postgres.example.com",
    "port": 5432,
    "user": "replication_user",
    "password": "secure-password",
    "database": "production",
    "ssl_mode": "require"
  }'
⚠️

Source Database Requirements: For peers used as replication sources, ensure PostgreSQL is configured with wal_level=logical and has sufficient max_replication_slots and max_wal_senders. See Configuration for details.

Error Responses

Status CodeErrorDescription
400Bad RequestMissing required fields or invalid values
401UnauthorizedMissing or invalid token
403ForbiddenUser does not have admin role
409ConflictPeer name already exists

Get Peer

Retrieve details for a specific peer.

Endpoint

GET /v1/peers/{name}

Permission: authed (any authenticated user)

Path Parameters

ParameterTypeDescription
namestringUnique peer name

Example

curl http://localhost:8112/v1/peers/production-db \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Update Peer

Modify an existing peer’s configuration.

Endpoint

PUT /v1/peers/{name}

Permission: adminOnly

Path Parameters

ParameterTypeDescription
namestringUnique peer name

Request Body

Provide any fields you want to update. All fields are optional:

FieldTypeDescription
hoststringDatabase hostname or IP address
portnumberPostgreSQL port
userstringDatabase username
passwordstringDatabase password
databasestringDatabase name
ssl_modestringSSL mode

Example

curl -X PUT http://localhost:8112/v1/peers/production-db \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "host": "prod-postgres-new.example.com",
    "password": "new-password"
  }'
⚠️

Active Mirrors: Updating a peer that is actively used by a mirror may cause connection errors. Consider pausing mirrors before updating peer credentials.

Delete Peer

Remove a peer configuration.

Endpoint

DELETE /v1/peers/{name}

Permission: adminOnly

Path Parameters

ParameterTypeDescription
namestringUnique peer name

Example

curl -X DELETE http://localhost:8112/v1/peers/production-db \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
🚫

Cannot Delete Active Peers: You cannot delete a peer that is currently used by an active mirror. Delete the mirror first, or the API will return an error.

List Tables

Retrieve all tables in a peer database.

Endpoint

GET /v1/peers/{name}/tables

Permission: authed (any authenticated user)

Path Parameters

ParameterTypeDescription
namestringUnique peer name

Response

Returns an array of table objects:

FieldTypeDescription
schemastringSchema name (e.g., public)
table_namestringTable name

Example

curl http://localhost:8112/v1/peers/production-db/tables \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

This endpoint is useful for discovering which tables are available before creating a mirror or adding tables to an existing mirror.

Test Connection

Test connectivity to a peer database and retrieve its PostgreSQL version.

Endpoint

POST /v1/peers/{name}/test

Permission: adminOnly

Path Parameters

ParameterTypeDescription
namestringUnique peer name

Response

FieldTypeDescription
successbooleanWhether the connection succeeded
versionstringPostgreSQL version string (if successful)

Example

curl -X POST http://localhost:8112/v1/peers/production-db/test \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Use this endpoint after creating or updating a peer to verify that BunnyDB can connect successfully before creating mirrors.

SSL Modes

PostgreSQL supports several SSL modes for encrypted connections:

ModeDescriptionUse Case
disableNo SSLDevelopment only, insecure
preferUse SSL if available, fall back to plainDefault, flexible
requireRequire SSL connectionProduction with SSL
verify-caRequire SSL and verify CA certificateHigh security
verify-fullRequire SSL and verify hostnameMaximum security
⚠️

Production Recommendation: Use require, verify-ca, or verify-full for production databases to ensure encrypted connections.

Common Workflows

Adding a Source Database

# Create the peer
curl -X POST http://localhost:8112/v1/peers \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "source-db",
    "host": "source.example.com",
    "port": 5432,
    "user": "replication_user",
    "password": "password",
    "database": "production",
    "ssl_mode": "require"
  }'
 
# Test connectivity
curl -X POST http://localhost:8112/v1/peers/source-db/test \
  -H "Authorization: Bearer <token>"
 
# List available tables
curl http://localhost:8112/v1/peers/source-db/tables \
  -H "Authorization: Bearer <token>"

Rotating Database Credentials

# Update the peer with new credentials
curl -X PUT http://localhost:8112/v1/peers/source-db \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "password": "new-password"
  }'
 
# Test the new credentials
curl -X POST http://localhost:8112/v1/peers/source-db/test \
  -H "Authorization: Bearer <token>"