A username is the name used to log into Confluence, eg.
|
|
Instructions For Changing Usernames
This document is for use with 3.5. If using an earlier version, please see the 3.4 version of the page. The following SQL commands are only tested for MySQL and PostgreSQL Databases. If you have any other database please contact your DBA to determine the equivalent queries. |
Usernames can only be changed through direct update to the Confluence database.
- If you have a database administrator, request that they approve the database-related steps described below
- If you are using JIRA user management, Revert from JIRA To Internal User Management
- Backup Confluence
If you are using MySQL, make sure you are not running in safe updates mode:
Create a
usermigrationtable:Usernames that will be changed must be placed in the
usermigrationtable with their current and planned usernames:- Run the following SQL commands:
If you have command line access to your database, download the scripts for PostgreSQL or MySQL then run them against your database:
PostgreSQL
MySQL
- Otherwise, run the following:
If your DB administration tool does not support multiple SQL queries, these must be entered individually:
PostgreSQL
MySQL
Reassign user preferences in the OS_PROPERTYENTRY table. Usernames in the OS_PROPERTYENTRY table need to be prefixed with 'CWD_'.
PostgreSQL
MySQL
Reassign personal spaces and settings associated with the old username to the new username. The tilda (~) is required as it is prepended to the space key of all personal spaces:
PostgreSQL
MySQL
- Each username is associated with a full name. For example, username 'jsmith' may have a full name of 'John M Smith'. If this fullname needs to be changed, modify the
first_name,lower_first_name,last_nameandlower_last_namein thecwd_usertable. Ensure thelower_columns are merely copies of their normal counterparts but with all letters in lower case. Then modify thedisplay_nameandlower_display_namecolumns so that they are thefirst_nameandlast_namecolumns or thelower_first_nameandlower_last_namecolumns put together but separated by a space.
Rebuild the Indexes
After all the updates, it's necessary to Rebuild the Indexes from Scratch
All old usernames in Confluence should now be replaced with the new usernames from the usermigration table.
RELATED TOPICS
|
Page:
Removing a Group
|
|
Page:
Adding a New User
|
|
Page:
Editing User Details
|
|
Page:
Adding or Removing Users in Groups
|
|
Page:
Global Permissions Overview
|
|
Page:
Viewing members of a group
|
|
Page:
Removing or Deactivating a User
|
|
Page:
Adding a Group
|
|
Page:
Permissions Overview
|
|
Page:
Changing Usernames
|
|
Page:
Global Groups Overview
|
|
Page:
Disabling the Built-In User Management
|
|
Page:
Setting up Anonymous Access
|
|
Page:
Searching For and Managing Users
|
|
Page:
Enabling or Disabling Public Signup
|









53 Comments
Hide/Show CommentsAug 22, 2006
Donald Jennings
Not sure how up to date the SQL above is for this problem. Below is the SQL I had to use to fix a naming problem for users as we moved from one LDAP service to another (their 6+2 login names were slightly different in some cases).
begin
for i in (select * from usermigration)
loop
delete from external_entities
where name = i.newusername;
update external_entities
set name = i.newusername
where name = i.oldusername;
update attachments
set creator = i.newusername
where creator = i.oldusername;
update attachments
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update content
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update content
set creator = i.newusername
where creator = i.oldusername;
update content
set username = i.newusername
where username = i.oldusername;
update content_label
set owner = i.newusername
where owner = i.oldusername;
update draft
set owner = i.newusername
where owner = i.oldusername;
update extrnlnks
set creator = i.newusername
where creator = i.oldusername;
update extrnlnks
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update links
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update links
set creator = i.newusername
where creator = i.oldusername;
update notifications
set username = i.newusername
where username = i.oldusername;
update notifications
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update notifications
set creator = i.newusername
where creator = i.oldusername;
update pagetemplates
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update pagetemplates
set creator = i.newusername
where creator = i.oldusername;
update spaces
set creator = i.newusername
where creator = i.oldusername;
update spaces
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update spacepermissions
set permusername = i.newusername
where permusername = i.oldusername;
update spacepermissions
set creator = i.newusername
where creator = i.oldusername;
update spacepermissions
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update contentlock
set creator = i.newusername
where creator = i.oldusername;
update contentlock
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
--update emailtemplates
--set creator = i.newusername
--where creator = i.oldusername;
--update emailtemplates
--set lastmodifier = i.newusername
--where lastmodifier = i.oldusername;
--update emailtemplates
--set username = i.newusername
--where username = i.oldusername;
update os_user
set username = i.newusername
where username = i.oldusername;
update trackbacklinks
set creator = i.newusername
where creator = i.oldusername;
update trackbacklinks
set lastmodifier = i.newusername
where lastmodifier = i.oldusername;
update OS_PROPERTYENTRY
set entity_name = replace(entity_name,i.oldusername,i.newusername)
where entity_id = (select entity_id from external_entities where entity_name = i.newusername);
end loop;
end;
Sep 11, 2006
Frank Stiller
The Article is outdated.
As Donald wrote, there are some new Tables which are not mentioned. Here is my SQL-Code running in Version 2.2.8, with MySQL 4.1:
update attachments x inner join usermigration u on
x.creator = u.oldusername
set x.CREATOR = u.newusername;
update attachments x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update content x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update content x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update content x inner join usermigration u on
x.username = u.oldusername
set x.username = u.newusername;
update content_label x inner join usermigration u on
x.owner = u.oldusername
set x.owner = u.newusername;
update draft x inner join usermigration u on
x.owner = u.oldusername
set x.owner = u.newusername;
update extrnlnks x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update extrnlnks x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update label x inner join usermigration u on
x.owner = u.oldusername
set x.owner = u.newusername;
update links x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update links x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update notifications x inner join usermigration u on
x.username = u.oldusername
set x.username = u.newusername;
update notifications x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update notifications x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update pagetemplates x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update pagetemplates x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update spaces x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update spaces x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update spacepermissions x inner join usermigration u on
x.permusername = u.oldusername
set x.permusername = u.newusername;
update spacepermissions x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update spacepermissions x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
update contentlock x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update contentlock x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
--update emailtemplates x inner join usermigration u on
--x.lastmodifier = u.oldusername
--set x.lastmodifier = u.newusername;
--update emailtemplates x inner join usermigration u on
--x.creator = u.oldusername
--set x.creator = u.newusername;
--update emailtemplates x inner join usermigration u on
--x.username = u.oldusername
--set x.username = u.newusername;
update os_user x inner join usermigration u on
x.username = u.oldusername
set x.username = u.newusername;
update trackbacklinks x inner join usermigration u on
x.lastmodifier = u.oldusername
set x.lastmodifier = u.newusername;
update trackbacklinks x inner join usermigration u on
x.creator = u.oldusername
set x.creator = u.newusername;
Hint:
Apr 28, 2009
Anonymous
Hi,
I have configured LDAP authentication and change my own non-LDAP username to LDAP user but I ended up having duplicate users. How do I go about fixing that part?
Thanks,
Amar
May 19, 2009
Arie Murdianto
If you have not contributed any content on your Confluence, you should be able to change directly in either your database (for local user) or LDAP. Thus, both users are actually different. After changing the username, you can delete one of them (user who has not contributed any content).
Nov 17, 2006
Stephen Morad
I found that I had to modify the confluencedb.script file as well as the confluence-home/database/confluencedb.log file (infact, after making changes in both, it looked like the confluencedb.log file got reset after restarting Confluence, so perhaps the only place requiring the change is confluencedb.script).
Jan 05, 2007
Brit Pair
I rewrote for SQL Server
Apr 21, 2007
Martin Cleaver [blended perspectives]
A mid way point should be to get this added to as a restful service accessible by the SOAP client.
Apr 26, 2007
Martin Cleaver [blended perspectives]
May 03, 2007
David Chui
I'm afraid you can't execute arbitrary SQL via the remote interface.
May 07, 2007
Martin Cleaver [blended perspectives]
Heh. I didn't want to.
I want to have these migration SQL scripts on the server and be able to invoke via soap something like:
This would wrap the table changes in appropriate transactions so no user was partially changed.
Presently you have to get into the database: it could be error prone and it involves too many different types of people: the administrator, database administrator, and plus possibly a programmer.
May 07, 2007
David Chui
Hi Martin,
I personally do not see how transactions could be partially completed if you have your DMLs live within a database transaction. In the most simplest case, only do a database commit at the end of the transaction. That should make it atomic. You just need to ensure that your database is ACID compliant.
May 08, 2007
Frank Stiller
To have only the sql-solution mentioned is good, as the xml-workaround was to faulty, but can you also say a workaround to update bodycontent (like linking to a user profile) which would be broken if you change the username?
That isnt a showstopper, just to have that in mind. I currently use a sql change to make the necessary field-updates and for the rest i check for profile links in the xml-entities file and change these values directly in the memo-field in the bodycontent. Maybe that could be the work of a xml-rpc tool or the like to change this more automatic. For a sql-replace the memo-field of the bodycontent is to huge, thats the reason why you cant do it like the field updates above.
May 09, 2007
David Chui
While it is possible to replace text in CLOB columns in some databases, I find it clumsy and I think your approach of replacing content text in Confluence backups using some regular expressions and then reimport them would be a better approach, for now.
Perhaps you'd like to comment about that in http://jira.atlassian.com/browse/CONF-4063?
Regards,
David
Jun 04, 2007
Martin Cleaver [blended perspectives]
None of these instructions work for Oracle.
Further, making admins perform database SQL commands to make up for this functionality is asking for trouble (especially given the many dialects of SQL).
Jun 04, 2007
Martin Cleaver [blended perspectives]
Nevertheless here's some instructions for Oracle. YMMV.
This will still leave your Recently Updated list pointing at non-existent personal spaces.
Feb 25, 2009
Anonymous
This script assumes that you are changing the username for all users -- in the event that you are not, you should add:
update attachments a
set a.creator = (select newusername from usermigration uwhere a.creator = u.oldusername)
where a.creator in (select oldusername from usermigration);
Jul 27, 2007
André Heie Vik
After changing username, the profile pictures are disabled. The user can see and select the uploaded pictures in Preferences, but they are disabled. How can I correct this in the database? (the pictures are attached to content of type userinfo, but I don't know how this is connected to the user)
Jun 06, 2011
Fennie Ng
Hi Andre,
Could you please raise a support ticket for this issue so that we can follow up from there? Alternatively, you may want to direct your questions to our Atlassian Answers as there might be other user/developers who have already implemented it and should be able to share their ideas with you.
Thank you.
Regards,
Fennie.
Jul 12, 2008
Bob Swift
What was the resolution to this?
Dec 07, 2011
Jörg Pfründer
We had the same problem until we realized that we use Confluence 3.4
Our SQL for Confluence 3.4 and Oracle:
Jul 30, 2007
Ólafur Bragason
Here is an updated version of the update statements in the original article (items 6, 7 and 8).
I dumped the Confluence database schema for version 2.5.5 and scanned through it for possible username and spacekey fields and added the missing statements. I am pretty sure I didn't leave anything out.
I left out OS_PROPERTYENTRY as I don't understand it's connection to external_entities (and didn't need to on my server).
The formatting should make it easier to change for other SQL dialects using global replace.
Aug 02, 2007
Ólafur Bragason
I found out the hard way that I had missed two fields:
Sep 04, 2009
Frank Stiller
FYI: spaces.spacekey is missing, is it?, and its called users table not user
but i could add draft.spacekey to my scripts by checking your commment
Jul 12, 2008
Bob Swift
We seem to have lost profile pictures and favorite for renamed users? I will submit a support request, but, perhaps someone has some experiences they can share.
Jul 18, 2008
Bob Swift
There are a few things missing and updates to this page are planned CONF-12437. Some are specifically related to OS_PROPERTYENTRY.
Jul 29, 2008
Anonymous
I found a few more columns that were not included; using these as well, I could get profile pictures to change and display normally. I also could add favorites successfully
UPDATE os_propertyEntry SET entity_name = LOC_newusername where entity_name=LOC_oldusername
UPDATE os_propertyEntry SET string_val='newusername' where string_val='oldusername'
Jul 29, 2008
Anonymous
screwed up the format; that last one is
'~newusername' and '~oldusername'
Aug 07, 2008
Paul-Dieter Klumpp
Can anybody confirm this piece of code that I now came up with?
It should work for a Confluence 2.8.2 installation and MySQL 5.0.51 as the database.
Aug 12, 2008
Azwandi Mohd Aris [Atlassian]
Hi there,
The instructions as outlined in the top section of this page have been tested, and recommended for changing usernames. However, I would suggest that you produce a backup of your database and Confluence before you proceed with these operations.
Cheers,
Azwandi
Aug 14, 2008
John W. Knight
Building off of all of this, and tested only on Postgres 8.3 with Confluence 2.9:
The /tmp/username_migration.csv file looks like:
The script has to be run as the Postgres superuser due to the copy command, and it allows you to update email address as well.
The premise behind our need for this tool is that we're integrating with our AD, and while IT said they would be going to first.last, they in fact stayed with firstinitiallastname, and so few of our Confluence users match the AD names, and this provides an easy bulk update mechanism.
However, it was written with the idea of ongoing username changes, which is why it stores a username migration index, so that you can keep the history of whose name changed when and where (hm, guess I could add a datestamp) but keep adding new users to run the tool against, say, because of marriage, etc.
The 4th column in the CSV allows you to specify a migration number if you so choose, otherwise it will auto-create it as 1 higher than the last run migration.
Questions, comments, direct here, I'll just watch the page. Atlassian, if you wanted to incorporate this into C4.x, I'd have NO problem letting you maintain this
John
Aug 14, 2008
John W. Knight
Oh, forgot to mention, it also handles duplicate user merging, just specify new_username the same (as per the Angelina example above), it'll merge all pages, edits, etc. to the ajolie name, and rename angie to ajolie_\d+ for easy removal.
John
Aug 14, 2008
Bob Swift
Very impressive! Thanks for posting. I sympathize with your comment:
Oct 06, 2008
Anonymous
I added one more line on here as we were using LDAP authentication
-- external_entities
update external_entities set name = v_new_username where name = v_old_username;
We were moving our usernames from email to another entry of LDAP.
Nov 18, 2008
Anonymous
Are there any updated bits of code for doing this on Oracle?
We've got two copies of each user that we need combining into one so that active directory works properly
Dec 18, 2008
Azwandi Mohd Aris [Atlassian]
Probably, you can refer to Martin Cleaver's comment?
Apr 24, 2009
Jonas Andersson
Could anyone that actually works at atlassian comment on exactly what tables and feilds that contain either the short (~user) or the long (user@domain.com) username on jira 3.13.2 and confluence 2.9.2? I need to have both converted for testing purpuse in a week and im afraid i might miss some small fields or alternavly accidentaly replace a binary string/string containing the name(especially the short name).
Regards
Jonas
Jun 17, 2009
Gurleen Anand [Atlassian]
Updated SQL queries, shared by one of the customers
Bryan Dobson, for MySQL 5.0 and above:Sep 04, 2009
Frank Stiller
my headache is getting bigger everytime i read these articles... Atlassian please do something about it.
For Example somehow the draft-table has dropped in the official document as well as in the updated sql from Gurleen. I am just going through step by step (at least the table in my databases if full of data), its my first replacement since i upgraded to 2.10... upgrading is a blessing (or something other ironic
)
edit: list of missing replacements from my point of view:
edit #2: ok after i digged through the list of John W. i think there were a bit more
edit #3: added draft.spacekey
edit #4: added content.draftspacekey and spacegrouppermissions.permusername (not sure with this one)
This is a complete SQL Script for MySQL 5.1 and Confluence 2.10 (used concat for tilde-operations)
complete means it run without errors, should be equally to John W.'s List and the renamed user could access/edit his stuff. Did not check whether atlassian included new fields/tables as of 2.9
Oct 09, 2009
Anonymous
Confluence 3.0.1 + Mysql 5
Oct 12, 2009
Frank Stiller
So nothing changed to the previously post and confluence 2.10? Or did i miss something.
Nov 02, 2009
Matthias Oesterheld
Here is an updated version of John W. Knights awesome Postgres Script. I also added one procedure for manual addition of users (to bypass the administrator restriction of the copy function).
Tested with Confluence 3.0.1 and Postgres 8.3
Nov 09, 2009
Frank Stiller
For the sake of completeness, i would suggest you add also:
Feb 23, 2011
François Nonnenmacher
You also need this to update followers/followees:
And I believe the last two lines are erroneous, the function names are as follows:
Mar 16, 2010
Pieter Thoma
Hi,
i just applied the queries to update my database, but still no users can logon.
What I did:
1. create db usermigration with old uname and new uname
2. ran the sql queries listed above for MySQL
3. restarted confluence
But still, I am not able to logon with the new user names.
What could be wrong?
Regards,
Pieter
Mar 16, 2010
Frank Stiller
Aug 09, 2010
Wallabee
I modified my LDAP setting from
BUT:
<usernameAttribute>sAMAccountName</usernameAttribute>to<usernameAttribute>cn</usernameAttribute>. With it I got an about 30% performance increase to open a page. I think the AD isn´t indexed forsAMAccountName.sAMAccoutnNameis always lowercase, thecnis a mix of upper and lower characters. At the end I had users setup twice in the system with different writing (e.g. "ConfluenceAdmin" and "confluenceadmin"). Resulting problems, e.g.:The above statements help a lot to cleanup the system, it took me some hours. Here my summary:
Check if there are double user entries in the external_entities and content table:
Create user mapping table
MySQL statement, other DB can differ:
fill table with the old and new usernames incl. the id´s from table external_entities:
Update with the ID´s from the table CONTENT:
Check if still other users in the content table (this can happen when username in
cnis lower case or the selects are wrong):Add this user to the table if necessary to update:
check result:
Update simple tables:
Personal Settings
This settings are defined, I don´t care (do not updated to the new user name):
'confluence.prefs.email.mimetype'
'confluence.prefs.email.show.diff'
'confluence.prefs.email.show.full.content'
'confluence.prefs.notify.for.my.own.actions'
'confluence.user.dashboard.spaces.selected.tab'
'confluence.user.last.login.date'
'confluence.user.previous.login.date'
'confluence.user.profile.picture'
'confluence.user.runtime.edit-wysiwyg'
'confluence.user.runtime.edit.show-labels'
'confluence.user.runtime.edit.show-restrictios'
'confluence.user.runtime.recent-changes.size'
'confluence.user.runtime.show-children'
'confluence.user.runtime.show-comments'
'confluence.user.site.homepage'
'confluence.user.time.zone'
'confluence.user.wysiwyg.contextmenu.on'
But for later clarifcation, I do NOT remove it from the table.
Update the string settings:
Get all user with duplicate string settings:
Get all entries:
Check if there still duplicate entries in:
Merge all remaining entries into new user/userid:
Update all department settings (TO BE CHECKED!)
Update the department/phone/location/... settings. I can fail (error message due to duplicate entry – key), then you need to update manually:
About Me
Get all user with about me entry:
Changed BODYCONTENT.CONTENTID to content id of new user name:
Get old entries of lower username:
They need to be delete manually:
Pictures:
Update attachments:
Remove image details of this users with duplicated entry of old username:
Remove duplicate entries of old user from ATTACHMENTS (above select statement).
Assign pictures to user:
Move the attachments of the jpeg/picture files from the old-content-id releated location to the new content-id location:
Get a mapping list:
Export list to Excel, insert 2 columns before oldcontid and 2 colomns before newcontid
Insert this formulas in
This describe the old/new diretory structure for the picture location. Copy down the formulars to the other cells in columns.
Open the the server
<confluence-home>/attachments/ver003/nonspacedfolder in a browser/explorer.For each entry, navigate to:
/B2/C2/D2/K2--> there must be a file (e.g. "1") for the picture ("1" mean the version 1)Check if a folder
/G2/H2/I2/K2exist: eather change the name of B2 to G2, C2 to H2, D2 to I2 or merge K2 into/G2/H2/I2.More details on the hierachy in the attachment folder see Hierarchical File System Attachment Storage.
(May someone find a better solution).
Update other username:
Update Old Users
Get all users:
Check result (there can be some users in, e.g. NON-LDAP users):
Remove old users from groups
Change old user/group mapping to newUser/group (may need to remove old user from groups before)
Check result:
Remove users not used the Wiki:
Update old user not used the wiki since change:
Remove old user entries
Draft pages:
The draft pages should be available again to the user. After system up, request to user to check the access. Otherwise send content to user:
Install Fix for label problem
When use use Confluence 3.1, you need ot fix the label problem
Remove Index
Move
<confluence-home>/indexto./index_OLD(can be deleted afterwards)Restart Confluence
Access to spaces / personal space
Additional help on page Fix Case Mismatches in Permissions
Rebuild Anchestor table:
<base url>/admin/permissions/pagepermsadmin.actionOther recommendations welcome.
Jan 17, 2011
Chris Hamono
Isn't the purpose of relational databases to prevent the same data everywhere? shouldnt the user name and details be stored in one table and then that is referenced by the other tables?
Change the user name in one spot and everything everywhere is updated?
Mar 14, 2011
Marian Finch [Atlassian]
Comment from Support Customer:
Once I understood the principle, I looked through the other tables and found another pair of update statements I believe should be included:
update content_perm
set creator = newusername from usermigration u
where creator = u.oldusername
update content_perm
set username = newusername from usermigration u
where username = u.oldusername
Mar 14, 2011
Anna Katrina Dominguez [Atlassian]
Hey Marian,
Can you please thank your customer for the input? Also, let them know we just updated the docs for 3.5 and went through all the tables again and they're right - content_perm should be in there too. However, there's one extra query that they missed from that table:
Thanks,
Anna
Mar 15, 2011
Anonymous
i wonder, werent these fields already in the scripts? i would be more happy to see Atlassian commits to confirm Scripts for different versions.
Apr 14, 2011
Marian Finch [Atlassian]
Thanks Anna! I will definitely thank and notify the customer of the changes.
Sep 14, 2011
Matt Doar (CustomWare)
That one is in the list I see on this page now
Dec 19, 2011
Anonymous
We did a domain migration and username change on Confluence 3.5.13 running on a MSSQL 2005
We had to modify the queries a little bit
7 B i
7 B ii
ignored
7 B iii
Add Comment