Skip to main content
IP restrictions control which networks can connect to your database, providing an additional layer of security beyond authentication. Manage IP restriction rules in the IP restrictions tab under Settings for your database, through the pscale database ip-restriction CLI commands, or through the IP restrictions API. Rules are configured at the database level and apply to all branches of the database. Every rule is copied to all existing branches as well as any branches created later. You cannot scope a rule to a single branch.

How IP restriction rules work

IP restriction rules act as an allowlist:
  • No rules configured: Connections are allowed from any IP address.
  • One or more rules configured: A connection is allowed only if it matches at least one rule on all three criteria:
    • IP ranges: The client’s IP address falls within one of the rule’s CIDR ranges.
    • Role: The rule’s Role field is empty (matches all roles) or matches the connection’s login username. PlanetScale’s routing layer strips the .<branch_id> suffix from the username before matching.
    • Database: The rule’s Database field is empty (matches all databases) or matches the PostgreSQL logical database name sent in the connection startup packet. If a client does not send a database name in the startup packet, PostgreSQL defaults it to the username.
Because each rule only grants access, rules combine additively:
  • All roles and all databases: Leave both Role and Database empty to allow the specified IP ranges for any role connecting to any logical database.
  • Specific role: Set Role and leave Database empty to allow the specified IP ranges for that role across all logical databases.
  • Specific database: Set Database and leave Role empty to allow the specified IP ranges for any role connecting to that logical database.
  • Specific role and database: Set both Role and Database to allow the specified IP ranges only when that role connects to that logical database.
Adding a rule scoped to a single role does not leave other roles unrestricted. Because rules are an allowlist, if your only rule is for role A, every other role is rejected from every IP address.Similarly, a role-scoped rule cannot restrict a role more than an all-roles rule does, because each rule can only allow connections that match it.
The Database field matches the PostgreSQL logical database name from the connection startup packet (for example, postgres), not a PostgreSQL schema within a database. In the PlanetScale API and the pscale CLI, this field and flag are named schema (--schema).

Creating an IP restriction rule

You must be a database or organization administrator to create or modify an IP restriction rule.
1
From the PlanetScale organization dashboard, select the desired database
2
Navigate to Settings from the menu on the left
3
Select the IP restrictions tab
4
Click “New rule”
5
Configure the rule settings:
  • Role (optional): Leave empty to allow all PostgreSQL roles, or specify a particular role username. Do not use the role’s descriptive name. Use only the username before the .<BRANCH_ID> suffix (for example, use pscale_api_<SUFFIX> rather than pscale_api_<SUFFIX>.<BRANCH_ID>), because routing strips .<BRANCH_ID> before matching.
  • Database (optional): Leave empty to allow all PostgreSQL logical databases, or specify a particular PostgreSQL logical database name (not a schema within a database). In the API and pscale CLI, this parameter is named schema (--schema).
  • IP ranges (required): Enter a comma-separated list of IP addresses or CIDR ranges (e.g., 1.2.3.4/32, 10.0.0.0/8)
6
Click “Create rule”

IP range format

The IP ranges field accepts:
  • Individual IP addresses in CIDR notation (e.g., 1.2.3.4/32)
  • IP ranges in CIDR notation (e.g., 10.0.0.0/8, 192.168.1.0/24)
  • Multiple entries separated by commas (e.g., 1.2.3.4/32, 10.0.0.0/8)

Editing an IP restriction rule

1
Navigate to Settings → IP restrictions
2
Click the menu icon (…) on the right side of the rule you want to edit
3
Select Edit from the menu
4
Modify the rule settings as needed:
  • Role: Change the role username or leave empty to match all PostgreSQL roles
  • Database: Change the PostgreSQL logical database name or leave empty to match all databases
  • IP ranges: Update the comma-separated list of IP addresses or CIDR ranges
5
Click “Update rule” to save your changes

Deleting an IP restriction rule

1
Navigate to Settings → IP restrictions
2
Click the menu icon (…) on the right side of the rule you want to delete
3
Select Delete from the menu
4
Review the confirmation dialog showing the rule details (role, database, and IP ranges)
5
Click “Delete rule” to confirm deletion, or “Cancel” to keep the rule
Deleting an IP restriction rule is irreversible and applies across all branches of the database:
  • Deleting a rule when other rules remain removes the access that rule granted. New connections relying on that rule will be blocked unless another rule allows them.
  • Deleting the last remaining rule removes all IP restrictions for the database and allows connections from all IP addresses on all branches.
Creating, editing, or deleting a rule only applies to connections established after the change. It does not impact or disconnect existing connections, even if they no longer match the configured rules.

Using IP restrictions with private connections

If you’re connecting to your database through AWS PrivateLink or GCP Private Service Connect, the source IP address that PlanetScale sees is not your application’s IP address or your VPC’s CIDR range. Instead, PlanetScale sees the private IP address from our internal network infrastructure that handles the private connection.

Restricting access to private connections only

If you want to ensure your database only accepts connections through PrivateLink or Private Service Connect (blocking all public internet access), you should configure your IP restrictions to allow the following RFC1918 private IP ranges: By allowing only these private ranges, you effectively block all connections from the public internet while still allowing connections through your private endpoint.
Adding IP restrictions to your database is independent from setting up PrivateLink or Private Service Connect. Simply enabling a private connection does not automatically block public internet access. You must explicitly configure IP restrictions if you want to enforce private-only connectivity.
Example configuration: To restrict a database to only accept connections through private endpoints, create an IP restriction rule with the following IP ranges:
This configuration allows connections from any of the RFC1918 private IP ranges while blocking all public internet traffic.

Best practices

When configuring IP restrictions rules:
  • Start with the most restrictive rules that meet your requirements
  • Use CIDR notation to define ranges efficiently (e.g., /24 for a subnet rather than listing individual IPs)
  • Document the purpose of each rule by using descriptive role names or organizing rules by application
  • Regularly audit your IP restrictions rules to remove access that is no longer needed
  • Consider creating separate roles for different applications or environments to enable fine-grained access control
  • Complement network restrictions with pg_strict for query-level protection against accidental mass mutations

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.