A patron is a person who uses a library; a client program uses a database.
A librarian assists patrons, helping decrease the time they spend trying to accomplish tasks at the library. Librarians are paid for their time. Databases can cache query results, indexes, and data pages in memory to answer client requests faster. Such caching uses valuable memory. Thus, both increase the efficiency of their respective systems, at the cost of system resources.
A patron may check out a book from the library, and take that book home, during which time he or she is the only one able to use the book. A database transaction may place a lock on a row or a table, preventing access for other transactions until it is finished. Thus, both of these restrict concurrent access to resources.
Some library items are not available for checkout: magazines and reference books often must be read in the library. Similarly, database systems use permissions to control and limit access to tables, schemas, and attributes.
Books are placed on shelves in aisles, close to some books (i.e. on the same shelf), but far from others (i.e. on a different floor). They're organized by the Dewey decimal system. Rows are placed on disk in pages and files, close to some rows and far from others -- based on rotational latency and seek time of the hard disk. Rows are organized by the clustered index.
Imagine how long it would take to find 15 books scattered throughout the library, given only their Dewey decimal numbers. How much faster would it be to find 15 books sitting on the same shelf? (Answer: seconds versus minutes) Similarly, it can be faster to read 10000 sequential rows from a database, than to read 15 randomly scattered rows.
A card catalog is a listing of all the books in the library, typically sorted by author. The advantage of such a listing is that books can easily and quickly be found by author (or any author cataloged attribute) -- simply find the author's entries in the card catalog, read off the Dewey decimal numbers, and locate the books. Similarly, database rows can be quickly searched using an indexed attribute. The index stores the column's values in sorted order, along with a primary key value or row pointer. This can dramatically decrease the search time and disk usage.