On 17 Aug 2015, at 7:52am, Paolo Bolzoni <paolo.bolzoni.brown at gmail.com> wrote:
> I have a program that materialize the subset of a database in a second > database for future use. > > To do so I create the database object on the OUTPUT database, create > tables, create the indexes, and vacuum it just in the case I reused an > old file. This will be faster, with almost the same effect, if you 1) delete tables you're going to recreate 2) VACUUM 3) create the new tables and indexes > After I attach the INPUT db and I copy the useful lines. > > The input db is about 13GB, so not really large, however the step on > this sql statement (where ? is of course binded to the db name) > > ATTACH DATABASE ? AS indb; > > requires several minutes (or more, it does not really seem to finish)! > Besides sqlite3 already created a 5GB journal file. > > > I am confused, why an attach database statement can be so slow? No idea. It shouldn't happen. I can only think it's trying to clear the cache and read some of the newly attached database into the cache. Try opening gthe output database then doing the ATTACH in the SQLite shell tool. Does it take the same about of time ? Also, out of interest, can you run "PRAGMA integrity_check" on all the database files involved ? Simon.