Connecting a Database to Your Gateway
Learn how to connect your database to a SuperAPI's gateway for intelligent cache invalidation
Why Database Connection is Required
SuperAPI requires access to your database to provide its core functionality: intelligent cache invalidation. By connecting directly to your database, SuperAPI can monitor data changes in real-time, ensuring your cached API responses remain fresh while maximizing performance.
This database monitoring is what enables SuperAPI to make traditionally "uncacheable" APIs cacheable by detecting exactly when and what data has changed, then selectively invalidating or updating only the affected cache entries.
For a list of supported database types and detailed configuration requirements, see our Supported Databases documentation.
Connecting Your Database
After creating your gateway, the next step is to connect your database. SuperAPI makes this process straightforward through its user interface.
Navigate to the "Databases" tab in your application dashboard
Click the "+ Add Database" button in the top right corner
In the "Configure your database" dialog, select your database type from the dropdown
Currently, SuperAPI supports PostgreSQL databases hosted on services like Amazon RDS and Google Cloud SQL.
Review and execute the required SQL operations
SuperAPI will show you the SQL script that needs to be executed on your database. You'll need to run these statements on your database to:
- Create a new user (
superapi_user
) with a secure password - Assign necessary permissions:
pg_read_all_stats
,pg_monitor
, andrds_replication
- Create a new publication (
superapi_publication
) for replication
These operations ensure SuperAPI has the correct access to monitor your database changes. You must execute these SQL statements using a database user with administrator privileges before proceeding.
The SQL scripts we provide handle all user creation and permission configuration. The script creates a superapi_user
with read-only access and specific replication privileges. While you can change the password in the script for added security, make sure you use the exact same password when entering database credentials in the later steps.
Enter your database credentials:
- Host: Your database hostname or endpoint (e.g.,
database-1.cpqftxv9qd2p.ap-south-1.rds.amazonaws.com
) - Port: The database port (typically 5432 for PostgreSQL)
- Username: Database username with appropriate permissions (typically
superapi_user
) - Password: Password for the database user
- Database Name: Name of your database
Verify logical replication status
SuperAPI will check if logical replication is enabled on your database. This feature is essential as it allows SuperAPI to track changes in your database tables and invalidate the relevant cached API responses.
If logical replication is not enabled, you'll need to enable it. See our Supported Databases documentation for instructions on enabling logical replication on different database platforms.
Select tables for monitoring
Choose which database tables SuperAPI should monitor for changes. These are typically the tables that contain data returned by your API endpoints.
SuperAPI will show any previously configured tables if you're reconnecting a database. You can add or remove tables based on your caching needs.
When you add new tables, SuperAPI will generate SQL queries that need to be run on your database. These queries typically:
- Add the tables to the publication to enable replication monitoring
- Set the replica identity to ensure complete change information is available
You'll need to execute these queries on your database to complete the setup for new tables.
Click "Next" to complete the database connection
What Happens Behind the Scenes?
When you connect your database, SuperAPI:
- Validates the connection credentials
- Verifies logical replication is enabled
- Sets up replication monitoring for selected tables
- Creates the necessary publication and replication slot
- Prepares to monitor data changes in real-time
This allows SuperAPI to detect changes made by any process, including:
- API operations
- Background jobs
- Direct database modifications
- Batch processes
Next Steps
After successfully connecting your database, the next step is to configure which API endpoints should be cached and how they relate to your database tables.
Next: Adding Endpoints
Learn how to configure API endpoints for caching