I’m trying to migrate my server to a new host, so I downloaded a backup file, and uploaded it to the new host. Installed a fresh copy of discourse, and followed the instructions to do so from the command line:
Unfortunately, the discourse restore databasename fails with:
ALTER TABLE
ALTER TABLE
ALTER TABLE
ERROR: could not create unique index "posts_search_pkey"
DETAIL: Key (post_id)=(36946) is duplicated.
EXCEPTION: psql failed: DETAIL: Key (post_id)=(36946) is duplicated.
/var/www/discourse/lib/backup_restore/database_restorer.rb:92:in `restore_dump'
/var/www/discourse/lib/backup_restore/database_restorer.rb:26:in `restore'
/var/www/discourse/lib/backup_restore/restorer.rb:51:in `run'
script/discourse:149:in `restore'
Seems there’s something wrong with the database file? Can someone give me some direction on how I can fix this error? I still have access to the original server, which seems to be running fine.
Is there some sql command or something I can run that will analyze (and fix?) the database before I download a backup?
./launcher enter app
su - postges
psql discourse
select id from post_search_data were post_id>86918 and post_id<86921;
--- when you get the id ----
delete from post_search_data where id=ID_FROM_LAST_QUERY
There could be more.
Perhaps someone else can provide more help but that’s about all I think I can do without being logged in to your server. If you need much more help, you can post in marketplace or contact me directly.
Or perhaps it’s safe to just wipe it away and have it get regenerated, but I’m not quite sure about that.
discourse=# reindex index concurrently "posts_search_pkey";
ERROR: could not create unique index "posts_search_pkey_ccnew2"
DETAIL: Key (post_id)=(116038) is duplicated.
discourse=# delete from post_search_data
where post_id = 116038;
DELETE 2
discourse=# delete from post_search_data
where post_id = 116038;
DELETE 0
discourse=# reindex index concurrently "posts_search_pkey";
ERROR: could not create unique index "posts_search_pkey_ccnew3"
DETAIL: Key (post_id)=(9336) is duplicated.
discourse=# delete from post_search_data
where post_id = 9336;
DELETE 1
.
.
.
.
discourse=# reindex index concurrently "posts_search_pkey";
REINDEX
Once everything seemed ok, I did a full backup and restored it on a new server with no issues.
I appreciate everyone’s time. I love discourse!
Lesson learned: check backups once in a while to be sure they’re good I keep daily backups, and then keep monthly “snapshots” too. The earliest backup I had that didn’t have a corrupted database was 4 months old