Learn to enable logs in Supabase with our step-by-step guide. Access your dashboard, set up log destinations, enable PostgreSQL extensions, and verify your configuration.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Access the Supabase Dashboard
To begin enabling logs in Supabase, access your Supabase project dashboard. Navigate to the Supabase website, log in with your credentials, and select the project for which you want to enable logs.
Step 2: Set Up a Log Destination
To enable logs, you must first set up a destination to where your logs will be sent. Supabase uses established PostgreSQL extensions for logging.
Step 3: Enable Extensions for Logging
You need to enable specific extensions in your database that can handle logging.
-- To enable the pg_stat_statements extension which helps in logging query statistics
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
-- Optionally, you can enable other extensions based on your logging needs:
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE EXTENSION IF NOT EXISTS pgaudit;
Ensure each command runs successfully before proceeding.
Step 4: Configure PostgreSQL for Logging
Supabase allows you to modify PostgreSQL parameters using the 'Database settings' within your dashboard. To configure your database for logging:
log_statement
and log_duration
. These settings allow you to log various activities:log_statement
can be set to none
, ddl
, mod
, or all
depending on what you need to log (DDL statements, modifications, or all statements).
Step 5: Customize Logging Behavior
Modify logging settings in the SQL editor according to your requirements:
-- For logging all statements
ALTER SYSTEM SET log\_statement = 'all';
-- For logging only DDL and modifications
ALTER SYSTEM SET log\_statement = 'mod';
-- For logging statement durations (query execution times)
ALTER SYSTEM SET log\_duration = 'on';
After setting these, reload the configurations by running:
SELECT pg_reload_conf();
Step 6: Verify Logging Setup
It's important to verify if your configurations have been applied correctly. You can do this by querying for recent log entries.
pg_stat_statements
view to check for recent queries and their statistics.
SELECT \* FROM pg_stat_statements ORDER BY calls DESC LIMIT 10;
Step 7: Manage and Monitor Logs Regularly
Regular monitoring and management of logs are crucial to maintaining database health. Set up alerts or periodically review logs to identify issues or optimize query performance.
By following these steps, you should be able to enable and configure logging within Supabase, allowing you to monitor database activity effectively.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.