,I%Berkeley DB: DB->close[P

DB->close





#include <db.h>

int#DB->close(DB *db, u_int32_t flags);





Description



GThe DB->close function flushes any cached database information to disk,Fcloses any open cursors, frees any allocated resources, and closes anyunderlying files.HSince key/data pairs are cached in memory, failing to sync the file withgthe DB->close or DB->sync function may result in inconsistent orlost information.

CThe flags parameter must be set to 0 or the following value:

<

DB_NOSYNC
Do not flush cached information to disk.

)The DB_NOSYNC flag is a dangerous option.?It should only be set if the application is doing logging (with@transactions) so that the database is recoverable after a systemAor application crash, or if the database is always generated from.scratch after any system or application crash.

IIt is important to understand that flushing cached information to disk@only minimizes the window of opportunity for corrupted data.EWhile unlikely, it is possible for database corruption to happen if aFsystem or application crash occurs while writing data to the database.JTo ensure that database corruption never occurs, applications must either:Euse transactions and logging with automatic recovery, use logging and>application-specific recovery, or edit a copy of the database,Fand, once all applications using the database have successfully called<DB->close, atomically replace the original database with the updated copy.



RWhen multiple threads are using the Berkeley DB handle concurrently, only a single'thread may call the DB->close function.

=Once DB->close has been called, regardless of its return, the)Berkeley DB handle may not be used again.

The DB->closeHfunction returns the value of errno on failure, and 0 on success.



Errors

RIf a fatal error occurs in Berkeley DB, the DB->close function may fail and returnFDB_RUNRECOVERY, at which point all subsequent database calls will alsoreturn DB_RUNRECOVERY.

The DB->close)function may fail and return errnoKfor any of the errors specified for the following Berkeley DB and C library functions:0DB->sync,DBcursor->c_close(3),dbc->c_am_destroy(3),6dbm_close,dbp->am_close(3), fflush(3), fprintf(3),free(3),Blog_unregister,8memp_close,=memp_fclose,;memp_fsync, memset(3), vfprintf(3),and vsnprintf(3).



See Also

8db_appexit,8db_appinit,8db_version, DB->close,4DB->cursor,.DB->del,,DB->fd,.DB->get,0DB->join,/db_open,.DB->put,0DB->stat,0DB->sync,;DBcursor->c_close,7DBcursor->c_del,6DBcursor->c_getand7DBcursor->c_put.
ÿÿ