> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pgw.sipmicro.services/llms.txt
> Use this file to discover all available pages before exploring further.

# Troubleshooting

> Find the cause of a failed registration, call, push, TLS connection, or startup in pgw by the status code or log line that you see, and fix it.

Each entry is named for what you see: a SIP status code, a log line, or a command's error. Find yours in the section for its area, and open it.

## Where to look first

If all you know is that the phone doesn't ring, answer these three questions. Each one checks one step on the way from the app to the PBX and back.

| Question | How to check | If the answer is no |
| - | - | - |
| Did the app register through pgw? | `pgw binding list` shows a binding for the user. | See [Registration](#registration). |
| Did the PBX send the call to pgw? | The log shows a `call ended` line for the call. | If the log shows `invite refused` instead, pgw refused the call, so see [Incoming calls](#incoming-calls). Otherwise, see [The app registers, but calls never reach pgw](#the-app-registers-but-calls-never-reach-pgw). |
| Did the push service accept the push? | The [push log](https://docs.pgw.sipmicro.services/push-log.md) shows a `call` event with a `2xx` status and no `error`. | See [Pushes](#pushes). |

A call to an app that was still connected has no event in the push log, because pgw sent no push.

If all three answers are yes, the push service took the push. The problem is most likely on the device or in the app. See [Handle a call push](https://docs.pgw.sipmicro.services/apps/integrate.md#handle-a-call-push).

To read the log, run `journalctl -u pgw`. For more detail, set `log_level: debug`. To see each SIP message, set `sip_log: true`.

## Registration

> [accordion] REGISTER gets 404 Unknown Domain
>
> **Cause**
>
> No upstream serves the host in the Request-URI. pgw matches the host by name against:
>
> * Each upstream's host, `domains`, and wildcards.
> * The domain table of a Kamailio upstream with `use_domain`.
>
> A domain that resolves to the PBX's address still gets `404`. On a managed upstream with domains, the domain of the To URI must be served too.
>
> **Fix**
>
> Do one of the following:
>
> * Add the domain with `pgw upstream update --id <id> --domains <list>`.
> * Create an upstream with `--host` set to the domain.
> * Add the domain to Kamailio's domain table. pgw reads the table every 60 seconds.
> * Set the app account's domain to the user's domain, so that the Request-URI and the To URI both name it. See [Add users at each domain](https://docs.pgw.sipmicro.services/upstreams/several-domains.md#add-users-at-each-domain).

> [accordion] REGISTER gets 401 Unauthorized again and again in managed mode
>
> **Cause**
>
> The app gets the same `401` for three different causes. To tell them apart, check which `reason` of `pgw_register_auth_failures_total` grows:
>
> | `reason` | Cause |
> | - | - |
> | `unknown_user` | pgw has no user with the app's username at the To URI's domain. |
> | `disabled_user` | The user exists and is disabled. |
> | `wrong_password` | The password in the app differs from the one that pgw stores. |
>
> **Fix**
>
> * Check the user in `pgw user list --upstream <id>`. Set the password with `pgw user set --id <user-id> --password`.
> * On an upstream with domains, set the app's account domain to the user's domain, or create the user there with `pgw user create --domain`.
> * On a Kamailio upstream, if only subscribers with an `ha1` fail, the `ha1` values use another realm. Create the upstream again with `--realm` set to Kamailio's realm. See [Match Kamailio's realm](https://docs.pgw.sipmicro.services/pbx/kamailio-user-source.md#match-kamailios-realm).

> [accordion] The app sends no second REGISTER after 401
>
> **Cause**
>
> pgw offered only methods that the app doesn't support. For example, it offered Bearer to an app that signs in with a password.
>
> With `log_level: debug`, the log shows `register challenged` with `offers` and a `cause`, such as `digest credentials, but app_auth is bearer`.
>
> **Fix**
>
> Set the upstream's `--app-auth` to a method that the app supports, or to `both`.

> [accordion] A token gets 401 with error="invalid\_token", or 403
>
> **Cause**
>
> pgw refused the token. `pgw_bearer_verifications_total` shows why:
>
> * `invalid` is a bad signature, issuer, audience, or expiry, or an unknown key.
> * `subject_mismatch` (`403`) is a `sub` that names another user than the To URI.
>
> With `log_level: debug`, the log shows `bearer token refused` with the rule that failed.
>
> **Fix**
>
> * Compare the token's `iss` and `aud` with `--bearer-issuer` and `--bearer-audience`.
> * Check the clocks of the issuer and pgw.
> * Check that the issuer's key set holds the signing key.

> [accordion] REGISTER gets 555 Push Notification Service Not Supported
>
> **Cause**
>
> No App matches the app's push parameters. On iOS, that is the bundle ID. On Android, it is the Firebase project ID or number. For a browser, the tenant has no web App.
>
> **Fix**
>
> Compare the app's push parameters with `pgw app list`. For an Android app that sends the Firebase project number, set `--fcm-project-number`.

> [accordion] REGISTER gets 400 Bad Push Parameters
>
> **Cause**
>
> The Contact's push parameters don't parse.
>
> If the response has `Warning: 399 pgw "push subscription host not allowed"`, the browser's push subscription isn't `https`, or its host isn't in `webpush_hosts`.
>
> **Fix**
>
> Check the app's push settings and version. For a browser, add its push service host to `webpush_hosts`, and restart pgw.

> [accordion] REGISTER gets 403 from the PBX
>
> **Cause**
>
> The password is wrong, or the AOR reached the PBX's contact limit.
>
> **Fix**
>
> Check the password in the app. For a full AOR, give the AOR room for at least `max_bindings_per_aor` plus 1 contacts, plus one for each other phone on the AOR. For the PBX setting, see the page for your PBX: [Asterisk](https://docs.pgw.sipmicro.services/pbx/asterisk.md#leave-room-for-one-more-contact) or [FreeSWITCH](https://docs.pgw.sipmicro.services/pbx/freeswitch.md#configure-the-sip-profile).

> [accordion] REGISTER gets 503 Service Unavailable
>
> | Also shows | Cause | Fix |
> | - | - | - |
> | `Retry-After: 5` | The source address exceeded `register_rate_per_ip`. | Raise `register_rate_per_ip` if many devices share one address. |
> | A long `Retry-After`, and the log shows `register source banned` | The address, or its IPv6 /64, sent too many wrong passwords. | Fix the refused account's password in its app. Then run `pgw ban lift --source <address>`, or wait. See [REGISTER ban](https://docs.pgw.sipmicro.services/security.md#register-ban). |
> | `Warning: 399 pgw "upstream transport tls is not supported"` | The upstream's transport is `tls`. | Run `pgw upstream update --id <id> --transport tcp`, or `udp` if the PBX doesn't accept TCP. |
>
> In the `register source banned` line, `banned_source` names the banned address or /64, and `aor` is the last refused account. Devices behind the same NAT share the ban.

> [accordion] The log shows register ban table full
>
> **Cause**
>
> pgw tracks wrong passwords from 65,536 source addresses at most. Until bans end and free the table, pgw doesn't count or ban new addresses.
>
> **Fix**
>
> Block the attacking networks at the firewall. To see the bans, run `pgw ban list`. `pgw_register_auth_failures_dropped_total` counts the refusals that pgw didn't track.

> [accordion] REGISTER gets 500 Server Internal Error with Retry-After: 5
>
> | Log shows | Cause | Fix |
> | - | - | - |
> | `upstream register failed` | The PBX refused the connection. The port or transport is wrong, or the PBX is down. | Check the upstream's port and transport, and the PBX. |
> | `user source unavailable` | pgw can't read Kamailio's database within 2 seconds. | Check the database, the network, and the password. To change the password, set `PGW_KAMAILIO_PASSWORD` and run `pgw upstream update --id <id>`. |
> | `kamailio domains not loaded; pgw keeps the last ones` | The domain table hasn't loaded since pgw started. pgw retries every 5 seconds. | Check that pgw's database user can reach and read the domain table. |
> | `federated upstreams not opened; their REGISTERs get 500` | pgw couldn't open the upstream's database, for example because its password doesn't decrypt. | Set `PGW_KAMAILIO_PASSWORD` and run `pgw upstream update --id <id>`. |
> | `upstreams claim the same domain` | Two Kamailio upstreams have the domain in their tables. | Remove it from one database. |
>
> In the `user source unavailable` line, `err` is `timeout`, `refused`, `authentication`, or `query`. Registered devices stay.
>
> A `500` without `Retry-After: 5` has another cause: the PBX answered the REGISTER with `503`. pgw passes it on as `500`, with the PBX's own `Retry-After` if the PBX sent one. Check the PBX's state and load.

> [accordion] REGISTER gets 502 Bad Gateway
>
> The `Warning` header names the cause.
>
> | Warning | Cause | Fix |
> | - | - | - |
> | `upstream refused the stored credentials` | The PBX refused pgw's stored password. The password changed at the PBX, or the AOR has no room. | Set a changed password with `pgw user set --id <user-id> --password`, or raise the PBX's contact limit. |
> | `upstream answered <status>` | The PBX refused pgw's REGISTER for another reason, such as a From domain policy. | Check the PBX's log for the REGISTER from pgw. For a Kamailio user source, check Kamailio's `domain` table. |
> | `upstream did not keep the Path` | `strict_path` is on, which is the default, and the PBX's answer dropped pgw's Path. | Make the PBX keep pgw's Path header, or use the `masquerade` contact strategy. If the PBX keeps Path without returning it, run `pgw upstream update --id <id> --strict-path=false`. |
>
> The first two warnings appear in managed mode.
>
> * With `upstream refused the stored credentials`, the app's password was right. After five refusals in a row, pgw removes the device. With per-user registration, pgw removes every device of the user.
> * With `upstream answered <status>`, the log shows `upstream rejected the registration`. pgw keeps retrying renewals.
> * With `upstream did not keep the Path`, pgw kept no binding.

> [accordion] REGISTER gets 504 Server Time-out
>
> **Cause**
>
> The PBX didn't answer within 20 seconds, or it answered `408`. Either a firewall drops the traffic, or the upstream's host is wrong. A UDP upstream on a wrong port also ends here.
>
> **Fix**
>
> Check the upstream's host and port. Check that pgw can reach the PBX through any firewall.

> [accordion] REGISTER gets 423 Interval Too Brief once, or the log shows upstream minimum expiry is above max\_expires
>
> **Cause**
>
> The PBX's minimum registration time is above the upstream's `max_expires`. pgw then uses the PBX's minimum, up to one day, until pgw restarts, so the next REGISTER succeeds. In managed mode, the app never sees the `423`.
>
> **Fix**
>
> Run `pgw upstream update --id <id> --max-expires <seconds>` with at least the PBX's minimum.

> [accordion] REGISTER gets 200 with Expires: 0, and the log shows upstream granted no registration
>
> **Cause**
>
> The PBX accepted the REGISTER but kept the contact for 0 seconds.
>
> **Fix**
>
> Check the PBX's limits on registration time and on contacts per AOR.

> [accordion] The log shows upstream unreachable, and pgw\_upstream\_up is 0
>
> **Cause**
>
> The upstream missed 3 OPTIONS in a row. The PBX is down, a firewall drops pgw's traffic, or the host or port is wrong. Registrations and calls through the upstream fail.
>
> **Fix**
>
> Check that the PBX listens on the upstream's port and that the firewall lets pgw reach it. pgw logs `upstream reachable` when the PBX answers again.

> [accordion] The log shows upstream did not keep pgw's Path
>
> **Cause**
>
> The PBX doesn't support Path or has it off, so it would send calls straight to the app. pgw counts each case in `pgw_upstream_path_missing_total`.
>
> **Fix**
>
> * Turn on Path support at the PBX. For the setting, see your PBX's documentation, or [Asterisk](https://docs.pgw.sipmicro.services/pbx/asterisk.md).
> * For a PBX without Path support, delete the upstream with `pgw upstream delete --id <id> --force`, and create it again with `--contact-strategy masquerade`.
> * To refuse such registrations, run `pgw upstream update --id <id> --strict-path`.

> [accordion] The log shows registration not undone at the upstream; the PBX keeps the Contact until it expires
>
> **Cause**
>
> pgw refused a registration that the PBX accepted. pgw then sent a REGISTER to remove it, and the PBX challenged that REGISTER. The PBX can send calls to the contact until it expires.
>
> **Fix**
>
> None needed. To remove the contact sooner, delete it on the PBX.

> [accordion] The log shows binding removed: its device registered another account after a reinstall
>
> **Cause**
>
> An iPhone app was reinstalled and signed in to another account with the same VoIP token. pgw removed the first account's binding. pgw answers the PBX's calls to that binding with `404` until the PBX registration expires.
>
> **Fix**
>
> None needed.

## Incoming calls

To find how a call ended, search the log for its Call-ID. pgw writes one `call ended` line for each device that the call rang. The line's `outcome` and `status` say how the call ended for that device.

```bash theme={null}
journalctl -u pgw | grep 'msg="call ended"' | grep 'call_id=<call-id>'
```

With `log_format: json`, search for `"msg":"call ended"`.

> [accordion] The call gets 403 Forbidden from pgw
>
> **Cause**
>
> The PBX sent the call from an address outside the upstream's `invite_source_cidrs`.
>
> **Fix**
>
> Run `pgw upstream update --id <id> --invite-source-cidrs <list>` with the address. See [Allow the PBX to send calls to pgw](https://docs.pgw.sipmicro.services/security.md#allow-the-pbx-to-send-calls-to-pgw).

> [accordion] The call gets 404 Not Found from pgw
>
> **Cause**
>
> pgw has no binding for the called contact, for example after the app unregistered.
>
> If the log shows `invite refused` with reason `no flow token in the request`, the PBX sent the call straight to the app's contact instead of through pgw's Path.
>
> **Fix**
>
> Check `pgw binding list`, and have the app register again.
>
> For a missing flow token, make the PBX keep pgw's Path header. For a PBX without Path support, use the `masquerade` contact strategy.

> [accordion] The call gets 486 Busy Here, and the log shows call push limit reached
>
> **Cause**
>
> The PBX sent the device more calls than `call_push_rate_per_binding` allows, for example in a forwarding loop or from a dialer that retries.
>
> **Fix**
>
> Fix the loop at the PBX. If the device takes that many calls, raise `call_push_rate_per_binding` or `call_push_burst_per_binding`.

> [accordion] Calls to a user fail at once with 480, and the user's other devices don't ring
>
> **Cause**
>
> The PBX's only contact for the user belongs to a device that pgw can't wake, because it has no push and isn't connected. In managed mode, pgw removes such a device within seconds of its connection closing. In passthrough mode, the device stays until its registration expires.
>
> **Fix**
>
> 1. In `pgw binding list`, find the user's bindings with `flow_alive` false and no `provider`.
> 2. Remove each with `pgw binding delete --binding <key>`.
> 3. Give the PBX room for more contacts. In passthrough mode or with `per_device`, allow at least `max_bindings_per_aor` plus 1 contacts, plus one for each other phone on the AOR. With per-user registration, allow one free contact per user. For the PBX setting, see the page for your PBX: [Asterisk](https://docs.pgw.sipmicro.services/pbx/asterisk.md#leave-room-for-one-more-contact) or [FreeSWITCH](https://docs.pgw.sipmicro.services/pbx/freeswitch.md#configure-the-sip-profile).

> [accordion] The call gets 480 Temporarily Unavailable after about 30 seconds
>
> **Cause**
>
> pgw pushed, but the app didn't register again within `hold_seconds`, 30 by default. The `Reason` is `device did not wake`.
>
> **Fix**
>
> Check that the push arrives, and that the app registers when it arrives. For slow devices, raise `hold_seconds`.

> [accordion] The app registers, but calls never reach pgw
>
> **Cause**
>
> The PBX ignores the Path, rewrites the Contact, or can't reach `hostname`, for example because pgw is behind NAT.
>
> **Fix**
>
> * Make the PBX keep pgw's Path header and the app's Contact as the app sent it, or use the `masquerade` contact strategy. For the PBX settings, see the page for your PBX: [Asterisk](https://docs.pgw.sipmicro.services/pbx/asterisk.md) or [FreeSWITCH](https://docs.pgw.sipmicro.services/pbx/freeswitch.md#how-freeswitch-routes-calls-to-pgw).
> * Behind NAT, set `upstream_hostname` and `upstream_port` to the public address that forwards to `upstream_listen`, and have the app register again. Keep `hostname` as the name in the apps' certificate check.

> [accordion] The caller keeps hearing ringing after the app answers, and the log shows relay response to upstream failed
>
> **Cause**
>
> The network dropped the answer on its way to the PBX. Over UDP, a large answer travels as several IP fragments, and some networks drop fragments.
>
> **Fix**
>
> Run `pgw upstream update --id <id> --transport tcp`, and have the app register again. The PBX must accept TCP.

> [accordion] The call connects with no audio
>
> **Cause**
>
> The PBX can't reach the phone for RTP.
>
> **Fix**
>
> Make the PBX send media to the address that it receives media from, and keep media flowing through the PBX. For the settings, see your PBX's documentation, or [Asterisk](https://docs.pgw.sipmicro.services/pbx/asterisk.md).

> [accordion] The phone keeps ringing after the caller hangs up
>
> **Cause**
>
> The app didn't act on the missed-call push.
>
> **Fix**
>
> On iOS, turn on remote pushes in the app. The missed-call push goes to the remote token.

## Requests during a call

> [accordion] A request from the app gets 403 Forbidden
>
> **Cause**
>
> The app sent the request on another connection than the one that it registered on, for example after a network change.
>
> **Fix**
>
> Have the app register again on every network change.

> [accordion] A request from the app gets 481 or 404 from the PBX, and the log shows route dropped
>
> **Cause**
>
> The PBX record-routes an address outside the upstream's `invite_source_cidrs`, such as its public address behind NAT or another cluster node. pgw sends the request to the upstream's address instead. There, the PBX can't match the request to the call.
>
> **Fix**
>
> Add each address that the log names in `host` to `--invite-source-cidrs`. pgw must be able to reach them.

> [accordion] A request from the PBX gets 480, and the log shows app flow closed; request not relayed
>
> **Cause**
>
> The app closed its connection during the call, for example because the device slept. pgw reaches an app only over the connection that the app opened.
>
> **Fix**
>
> Keep the app connected during calls, with keepalives more often than `app_idle_timeout`.

> [accordion] A request from the app gets 480 with sips requires a TLS upstream
>
> **Cause**
>
> The app used a `sips:` URI, which requires TLS on every hop. pgw reaches PBXs over UDP or TCP only. The log shows `sips request refused; the upstream has no TLS`.
>
> **Fix**
>
> Configure the app to use `sip:` URIs with TLS transport. The app's connection to pgw stays encrypted.

> [accordion] A request gets 500 from pgw, and the log shows relay request failed or relay to app failed
>
> **Cause**
>
> The other side answered `503`, or pgw couldn't reach it.
>
> **Fix**
>
> Check the other side's load. Check that pgw can reach it.

> [accordion] A request gets no response, and the log shows request timed out
>
> **Cause**
>
> The other side didn't answer within 32 seconds. pgw answers `408` only to INVITE, so the sender's own transaction times out.
>
> **Fix**
>
> Check that the other side is reachable and answers the method.

## Pushes

> [accordion] No push arrives
>
> **Cause**
>
> The push service refused the push, or the credentials don't match the app build.
>
> **Fix**
>
> Check the status and error in the [push log](https://docs.pgw.sipmicro.services/push-log.md). To test one device, run `pgw binding test-push --binding <key>` with a key from `pgw binding list`.

> [accordion] APNs returns 400 BadDeviceToken
>
> **Cause**
>
> The App's APNs environment doesn't match the build.
>
> **Fix**
>
> Use `sandbox` for builds from Xcode, and `production` for TestFlight and App Store builds.

> [accordion] pgw binding list shows a dead\_reason
>
> **Cause**
>
> The push service reported the token invalid, and pgw couldn't delete the binding, usually because the database failed. The log shows `dead binding not removed`. pgw sends the binding no pushes.
>
> **Fix**
>
> None needed. pgw deletes the binding at the next renewal scan in managed mode, or when its registration expires.

> [accordion] An Android app gets no push after it was closed
>
> **Cause**
>
> The app was force-stopped.
>
> **Fix**
>
> Open the app once. Close it by swiping it away, not with **Force stop**.

> [accordion] A push event shows push: skipped
>
> **Cause**
>
> On iOS, the app registered no remote token, so pgw skips missed-call and refresh pushes. A web app gets only call and test pushes.
>
> **Fix**
>
> On iOS, turn on remote pushes in the app.

> [accordion] A web push event shows push service host not allowed
>
> **Cause**
>
> The subscription's host isn't in `webpush_hosts`.
>
> **Fix**
>
> Add the host to `webpush_hosts`, and restart pgw.

## TLS and app connections

> [accordion] The app doesn't connect
>
> **Cause**
>
> The app rejected pgw's certificate, or port 5061 is blocked.
>
> **Fix**
>
> [Install a TLS certificate](https://docs.pgw.sipmicro.services/deploy/tls.md) from a public certificate authority, and open 5061/tcp.

> [accordion] The log shows app TLS handshake failed
>
> **Cause**
>
> The line's `err` names the cause: `bad certificate` when the app rejected the certificate, or `first record does not look like a TLS handshake` when the app used plain TCP.
>
> **Fix**
>
> Check that the certificate covers `hostname`, and that the app uses TLS.

> [accordion] The app's REGISTER gets no answer
>
> **Cause**
>
> The app sent it to port 5060. pgw takes REGISTER only on the app listener.
>
> **Fix**
>
> Set the app's transport to TLS and its port to 5061.

> [accordion] New app connections fail at a steady number
>
> **Cause**
>
> pgw reached its open-file limit. At startup, it logged `open-file limit below app_max_connections; raise LimitNOFILE or lower app_max_connections`.
>
> **Fix**
>
> [Raise the open-file limit](https://docs.pgw.sipmicro.services/tune-the-host.md#raise-the-open-file-limit), or lower `app_max_connections`.

## Startup

> [accordion] pgw exits at startup
>
> pgw writes the reason to standard error after `pgw: `, and exits with status 1.
>
> | Error contains | Fix |
> | - | - |
> | `field <key> not found` | Remove the key. It is misspelled, or a later release added it and this release doesn't know it. See [Configuration keys by release](https://docs.pgw.sipmicro.services/upgrade.md#configuration-keys-by-release). |
> | `set PGW_MASTER_KEY or PGW_MASTER_KEY_FILE` | Set one of them in the unit's environment. |
> | `PGW_MASTER_KEY and PGW_MASTER_KEY_FILE are both set; set only one` | Remove one of them. |
> | `master key file <file> has mode 644; make it readable by its owner only` | Run `chmod 600` on the key file. |
> | `PGW_BOOTSTRAP_TOKEN must have at least 32 characters` | Create a longer token. |
> | `load certificate:` | Check that `tls_cert_file` and `tls_key_file` exist, the `pgw` user can read them, and they form a pair. |
> | `data_dir is in use by another pgw process` | Stop the other process. |
> | `bind: address already in use` | Stop the program that holds the port, or change the listener. |

> [accordion] The log shows upstream uses TLS, which pgw doesn't support
>
> **Cause**
>
> pgw doesn't connect to PBXs over TLS. pgw answers the upstream's REGISTERs, and the apps' requests toward the upstream, with `503`.
>
> **Fix**
>
> Run `pgw upstream update --id <id> --transport tcp`, or `udp` if the PBX doesn't accept TCP.

> [accordion] The log shows upstream has a DNS name and no invite\_source\_cidrs; pgw refuses its calls
>
> **Cause**
>
> No prefix allows the PBX's addresses, so pgw answers its calls with `403`.
>
> **Fix**
>
> Run `pgw upstream update --id <id> --invite-source-cidrs <list>` with the PBX's addresses.

## Configuration changes

> [accordion] An upstream change fails with 400 and is a wildcard on a public suffix
>
> **Cause**
>
> A wildcard covers a single label, such as `*.lan`, or a public suffix, such as `*.co.uk`.
>
> **Fix**
>
> List a name under the suffix, such as `*.example.com`. pgw checks every domain on any change, so remove the wildcard before you change the upstream.

> [accordion] An upstream change fails with 409 and is already served by another upstream
>
> **Cause**
>
> One of the following is true:
>
> * Another of your upstreams has the name.
> * Another tenant has a name that yours equals, falls under, or covers. The other tenant's name can be an upstream's host, a domain, a wildcard, or a domain in a Kamailio domain table.
>
> **Fix**
>
> Remove the name from your other upstream, or use another name. The tenant that listed a name first keeps it.

> [accordion] The log shows another tenant's kamailio domains hold the domain; pgw's configuration keeps it
>
> **Cause**
>
> Another tenant's Kamailio domain table gained a domain that the upstream in `upstream_id` already lists. REGISTERs still go to that upstream.
>
> **Fix**
>
> Remove the domain from the Kamailio table, or from the upstream if the other tenant should serve it.

> [accordion] A domain change fails with 409 and every user of an upstream with domains needs a domain that it serves
>
> **Cause**
>
> The change would leave a managed user at a domain that the upstream doesn't serve. Either you added the first domains to an upstream whose users have none, or you removed a domain that users still have.
>
> **Fix**
>
> * To add the first domains, give each user a domain in the same `pgw config sync`, with `--prune`.
> * To remove a domain, delete its users first.
>
> See [Add users at each domain](https://docs.pgw.sipmicro.services/upstreams/several-domains.md#add-users-at-each-domain).

> [accordion] pgw upstream create --user-source kamailio fails with connect, domain table, or subscriber table
>
> **Cause**
>
> pgw couldn't connect to the database, or couldn't read the named table.
>
> **Fix**
>
> Check the `--kamailio-` flags and the database user's grants. See [Create the database user](https://docs.pgw.sipmicro.services/pbx/kamailio-user-source.md#create-the-database-user).

## Next steps

> [card] [SIP responses](https://docs.pgw.sipmicro.services/reference/sip-responses.md)
>
> Look up a status code that this page doesn't list.

> [card] [Logs](https://docs.pgw.sipmicro.services/logs.md)
>
> Follow one device or call through the log by its fields.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.