PostgreSQL has its own settings for query timeouts. You might want to check those. You might also want to figure out why these queries take so long. With proper indices, appropriate RAM allocations, and a decent LAN, you should be able to return hundreds of thousands of history records in a few seconds.
FWIW, the settings in postgresql.conf “out-of-the-box” are only appropriate for the wimpiest machines–think embedded applications. Any real DB hardware will need substantial increases to the memory usage settings.