From owner-freebsd-questions@freebsd.org Tue Oct 18 14:05:56 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1EA9AC1656C for ; Tue, 18 Oct 2016 14:05:56 +0000 (UTC) (envelope-from frank@woodcruft.co.uk) Received: from b.painless.aa.net.uk (b.painless.aa.net.uk [81.187.30.52]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DDDEFDEE for ; Tue, 18 Oct 2016 14:05:55 +0000 (UTC) (envelope-from frank@woodcruft.co.uk) Received: from woodcruft.co.uk ([81.187.49.114] helo=lime.woodcruft.co.uk) by b.painless.aa.net.uk with esmtp (Exim 4.77) (envelope-from ) id 1bwV1X-0007S1-PK; Tue, 18 Oct 2016 15:05:52 +0100 Received: by lime.woodcruft.co.uk (Postfix, from userid 1001) id DF9966F318; Tue, 18 Oct 2016 15:05:31 +0100 (BST) Date: Tue, 18 Oct 2016 15:05:31 +0100 From: Frank Shute To: Valeri Galtsev Cc: Steve O'Hara-Smith , freebsd-questions@freebsd.org Subject: Re: pw add user slow Message-ID: <20161018140531.GA1080@lime.woodcruft.co.uk> Reply-To: Frank Shute Mail-Followup-To: Valeri Galtsev , Steve O'Hara-Smith , freebsd-questions@freebsd.org References: <20161018074415.0f6575675db30d0b83d9b8ec@sohara.org> <60719.69.209.239.247.1476794773.squirrel@cosmo.uchicago.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <60719.69.209.239.247.1476794773.squirrel@cosmo.uchicago.edu> X-Face: *}~{PHnDTzvXPe'wl_-f%!@+r5; VLhb':*DsX%wEOPg\fDrXWQJf|2\,92"DdS%63t*BHDyQ|OWo@Gfjcd72eaN!4%NE{0]p)ihQ1MyFNtWL X-Operating-System: FreeBSD 11.0-PRERELEASE amd64 X-Organisation: 'woodcruft.co.uk' User-Agent: Mutt/1.6.1 (2016-04-27) X-Painless-Spam-Score: 0.2 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Oct 2016 14:05:56 -0000 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 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, -- Frank https://woodcruft.co.uk/