The Patriot Act in the US allows government agencies to obtain your personal library account information. In this article in the Nation it is stated that “Under the Patriot Act, the government can demand library records via a secret court order and without probable cause that the information is related to a suspected terrorist plot. It can also block the librarian from revealing that request to anyone. Nor does the term “records” cover only the books you check out; it also includes search histories and hard drives from library computers.”
Here in Canada, with Bill C51 just passed last week, it is not yet known if library records and search histories from public computers will be accessible to CSIS and other government agencies, but it is possible. To read more on the American situation, read this article in the Nation.