Skip to content

Instantly share code, notes, and snippets.

@starkayc
Last active April 25, 2025 09:31
Show Gist options
  • Select an option

  • Save starkayc/36978ae9b992099656d4709bfee31ac9 to your computer and use it in GitHub Desktop.

Select an option

Save starkayc/36978ae9b992099656d4709bfee31ac9 to your computer and use it in GitHub Desktop.
Clear Data on Umami Dashboard

πŸ”§ Deleting a Session Record in PostgreSQL (Docker)

This guide walks you through executing the following SQL command inside a PostgreSQL Docker container:

DELETE FROM session WHERE session_id = 'id_visitor';
DELETE FROM website_event WHERE session_id = 'id_visitor';

πŸ›Ÿ Step 0: Backup the Database (Recommended)

Before making any changes, it’s always a good idea to back up your data.

docker exec -t umami-db pg_dumpall --clean --if-exists --username=umami | gzip > "/path/to/backup/dump.sql.gz"

Replace /path/to/backup/dump.sql.gz with your desired local backup path.
Make sure the umami user exists and has sufficient privileges.


πŸ“¦ Step 1: Find Your PostgreSQL Container

Run the following command to list all running containers:

docker ps

Look for the one using the postgres image. Note the container name or container ID (e.g. umami-db).


🐚 Step 2: Access the PostgreSQL Shell (psql)

Use docker exec to open an interactive terminal to the container and connect to the database:

docker exec -it <container_name_or_id> psql -U <username> -d <database>

Replace the placeholders:

  • <container_name_or_id> β€” your PostgreSQL container name or ID
  • <username> β€” typically umami
  • <database> β€” your database name (e.g. umami)

Example:

docker exec -it umami-db psql -U umami -d umami

🧼 Step 3: Run the DELETE Command

Once inside the psql shell, run:

DELETE FROM session WHERE session_id = 'id_visitor';
DELETE FROM website_event WHERE session_id = 'id_visitor';

Replace 'id_visitor' with the actual session ID you want to remove.

βœ… If successful, it will return:

DELETE 1

(or another number depending on how many rows were affected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment