Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -4097,17 +4097,10 @@ assert( db || pPager->pWal==0 ); sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize, (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp) ); pPager->pWal = 0; -#endif -#ifdef SQLITE_SERVER_EDITION - if( pPager->pServer ){ - sqlite3ServerDisconnect(pPager->pServer, pPager->fd); - pPager->pServer = 0; - sqlite3_free(pPager->zJournal); - } #endif pager_reset(pPager); if( MEMDB ){ pager_unlock(pPager); }else{ @@ -4121,14 +4114,28 @@ ** database and close the journal file without attempting to roll it ** back or finalize it. The next database user will have to do hot-journal ** rollback before accessing the database file. */ if( isOpen(pPager->jfd) ){ + if( pagerIsServer(pPager) ){ + assert( pPager->journalMode==PAGER_JOURNALMODE_PERSIST ); + pPager->journalMode = PAGER_JOURNALMODE_DELETE; + /* If necessary, change the pager state so that the journal file + ** is deleted by the call to pagerUnlockAndRollback() below. */ + if( pPager->eState==PAGER_OPEN ) pPager->eState = PAGER_READER; + } pager_error(pPager, pagerSyncHotJournal(pPager)); } pagerUnlockAndRollback(pPager); } +#ifdef SQLITE_SERVER_EDITION + if( pagerIsServer(pPager) ){ + sqlite3ServerDisconnect(pPager->pServer, pPager->fd); + pPager->pServer = 0; + sqlite3_free(pPager->zJournal); + } +#endif sqlite3EndBenignMalloc(); enable_simulated_io_errors(); PAGERTRACE(("CLOSE %d\n", PAGERID(pPager))); IOTRACE(("CLOSE %p\n", pPager)) sqlite3OsClose(pPager->jfd); Index: test/server2.test ================================================================== --- test/server2.test +++ test/server2.test @@ -92,10 +92,25 @@ } {1} do_test 2.8 { execsql COMMIT execsql { SELECT * FROM t1 } db2 } {1 2 5 6} +db2 close + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b); +} +do_test 3.1 { + glob test.db* +} {test.db-journal0 test.db test.db-hma} +do_test 3.2 { + db close + glob test.db* +} {test.db} finish_test