I changed the URL of my discourse site, and am following the directions in Change the domain name or rename your Discourse. When attempting to run remap, I am repeatedly getting the following error. It keeps telling me to re-run the script but then the same error occurs each time.[1]
I’m not sure what my next move is here and would be grateful for guidance. Thanks in advance!
root@digitallysovereign:/var/discourse# ./launcher enter app
x86_64 arch detected.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): YES
Remapping tables on default...
ai_api_audit_logs=919
ai_secrets=1
backup_metadata=1
browser_pageview_events=3664
Error: ERROR: duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL: Key (date, normalized_referrer)=(2026-07-01, digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): YES
Remapping tables on default...
Error: ERROR: duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL: Key (date, normalized_referrer)=(2026-07-01, digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): YES
Remapping tables on default...
Error: ERROR: duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL: Key (date, normalized_referrer)=(2026-07-01, digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
I know the definition of insanity is to repeat the same thing over and over again and to expect a different result! ↩︎
looks like a constraint collision in the postgres analytics table. your database already includes records of the new domain on specific dates so the remap tool is likely creating duplicates and postgres is rejecting them.
i would try to delete the old domain records in the specific table only for the dates where the new domain already has data in order to preserve historical data and unblock the remap tool. do a safety backup first though.
try this:
cd /var/discourse
./launcher enter app
# create a safety backup
discourse backup
# enter the database console
sudo -u postgres psql discourse
/* find the exact table name tied to this index */
SELECT tablename
FROM pg_indexes
WHERE indexname = 'idx_bprd_rollups_date_referrer_unique';
assuming the query above returns browser_pageview_rollup_details then use that table name in the next query
/* delete the colliding analytics records */
DELETE FROM browser_pageview_rollup_details
WHERE normalized_referrer = 'discourse.tobiaseigen.org'
AND date IN (
SELECT date
FROM browser_pageview_rollup_details
WHERE normalized_referrer = 'digitallysovereign.org'
);
/* exit postgres */
\q
What I do is backup the database, change the URL, and then restore and let the Discourse remapper do the job. That code gets used by Discourse hosting and if it fails someone who can fix it will notice.
But yeah, those referrer links have caused all kinds of issues.
discourse db doesn’t work for me - I am using sudo -u postgres psql discourse.
The table returned by the first query was actually browser_pageview_referrer_daily_rollups so I used that in the second query.
Now I am getting a different error. When I run that second query again it does not delete anything.
Error: ERROR: duplicate key value violates unique constraint "idx_bprd_rollups_date_referrer_unique"
DETAIL: Key (date, normalized_referrer)=(2026-06-30, digitallysovereign.org/c/members/32) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
ok i guess the initial query used exact matching and it missed all the rows with paths attached. i would try this sql query i think (i can’t really test any of this because i have no need to change a domain name on my nameserver).
DELETE FROM browser_pageview_referrer_daily_rollups old_table
WHERE old_table.normalized_referrer LIKE '%discourse.tobiaseigen.org%'
AND EXISTS (
SELECT 1
FROM browser_pageview_referrer_daily_rollups new_table
WHERE new_table.date = old_table.date
AND new_table.normalized_referrer = REPLACE(old_table.normalized_referrer, 'discourse.tobiaseigen.org', 'digitallysovereign.org')
);
\q
if that works without error then run the remap tool and rebake rake task i posted above.
i did do a forum migration to a new server and new domain name a few months ago, but the remap tool worked perfectly for me the first time.
I am inching my way through the database, it seems. 24 records were deleted! Now I am at unique_post_links.
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): yes
Remapping tables on default...
browser_pageview_referrer_daily_rollups=1466
categories=2
chat_message_links=4
chat_message_search_data=4
chat_messages=5
discourse_activity_pub_collections=1
discourse_activity_pub_objects=1
drafts=4
email_logs=797
group_histories=2
groups=2
incoming_emails=21
moved_posts=2
notifications=10
post_localizations=51
post_revisions=31
post_search_data=226
posts=774
site_settings=1
stylesheet_cache=1168
Error: ERROR: duplicate key value violates unique constraint "unique_post_links"
DETAIL: Key (topic_id, post_id, url)=(581, 3696, https://digitallysovereign.org) already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.
SELECT tablename
FROM pg_indexes
WHERE indexname = 'unique_post_links';
should return topic_links? thus this is the next logical step:
DELETE FROM topic_links old_link
WHERE old_link.url LIKE '%discourse.tobiaseigen.org%'
AND EXISTS (
SELECT 1
FROM topic_links new_link
WHERE new_link.topic_id = old_link.topic_id
AND new_link.post_id = old_link.post_id
AND new_link.url = REPLACE(old_link.url, 'discourse.tobiaseigen.org', 'digitallysovereign.org')
);
\q
i think this is near the end of the database schema so it should likely be the final hurdle (i hope) before running the remap and rake task i posted above…
root@digitallysovereign-app:/var/www/discourse# discourse remap discourse.tobiaseigen.org digitallysovereign.org
Rewriting all occurrences of discourse.tobiaseigen.org to digitallysovereign.org
WILL RUN ON 'default' DB
THIS TASK WILL REWRITE DATA, ARE YOU SURE (type YES): yes
Remapping tables on default...
topic_links=1449
topic_search_data=11
topics=11
user_auth_token_logs=5
user_histories=131
Done
i was just misremembering because it’s rare that i do this sort of sql in the container. i did think that was the correct command. i think it’s because Discourse has built in commands like discourse backup and discourse remap.
yea the reason that this command cannot be added is it would have to vary according to the database architecture. i tried a PR but the actual command won’t work because it is different for say, standard install vs dual container and multisite. the script lives inside the discourse core container, so even if the admin enters the correct database container (in non-standard install), it will fail because the script where the command would be stored (script/discourse) is executed outside of it in say web_only.yml for a dual container build. basically the only way this command could work is for a standard install where the app and database are in the same container.