pw add user slow

Paul Macdonald paul at
Tue Oct 18 14:17:17 UTC 2016

On 18/10/2016 15:05, Frank Shute wrote:
> On Tue, Oct 18, 2016 at 07:46:13AM -0500, Valeri Galtsev wrote:
>> On Tue, October 18, 2016 1:44 am, Steve O'Hara-Smith wrote:
>>> On Mon, 17 Oct 2016 23:36:33 +0100
>>> Paul Macdonald <paul at> wrote:
>>>> Hi,
>>>> I have to migrate an imap server, which uses about 6000 local accounts
>>>> for mail delivery
>>>> I'm using a script that creates system acounts using:
>>>> /usr/sbin/pw adduser $LOCAL_USER -u$UID-gGID-d $PATH -s/bin/false
>>>> I'm finding this grows ever more slow, up to 10 seconds per account on a
>>>> SATA box  , and on a test SSD box ( 20 acc's per second initially) even
>>>> that slows to about 1 account created per second.
>>>> why does this slow down as more accounts are added?
>>> 	Because for each one it updates text files (passwd and
>>> master.passwd) and regenerates databases (pwd.db and spwd.db) from the
>>> text
>>> files. The fastest way to do this sort of thing is to directly update
>>> passwd and master.passwd and then run pwd_mkdb.
>> It appears to be sufficient to only edit master.passwd; pwd_mkdb will
>> re-generate passwd file from master.passwd.
> There's a tool for that: vipw(8)
> It uses $EDITOR if set, vi as default.
> If using vi/vim then fire up vipw and:
> :r!myscript
> will stick stdout from myscript into the buffer where the cursor is. Then:
> :wq
> and vipw will write it if it's conformant and then call pwd_mkdb to do it's
> business.
> The OP will also have to edit /etc/group to add his users to the appropriate
> group(s).
> Doesn't the imap server have an option for using a relational database rather
> than filling passwd up? I'd go for that option if it does.
> Regards,
manually writing to the master passwd and running pwd_mkdb was a lot 
quicker, thanks

at 10 seconds per account, 6500 would take a long time... (16hrs!)

the system accounts are for sendmail delivery to mailboxes, possibly a 
good time to take a look at exim/postfix.


Paul Macdonald
Web and video hosting
t: 0131 5548070
m: 07970339546
e: paul at
40 Maritime Street

Virtual Servers from £50.00pm
High specification Dedicated Servers from £150.00pm


More information about the freebsd-questions mailing list