its not the locks, you just dont have an index on that ip column. running a
select count(*)
without a proper b-tree index forces a full table scan every single time. check your
EXPLAIN ANALYZE
output to see if its actually hitting the disk or just doing a sequential scan.