Some SQLs sometimes take all available RAM I'm running postgresql server on Windows Server 2008, which has 6GB of ram. My dataset is something near 1,5GB big. 

I have problems, when I run specific SQLs in table, which has 51mio of records. The fields which I use in SQLs are indexed (alarm, id_elektrarna, id_razsmernik). Below is the ANALYZE SQL, which causes problems. Do you have any suggestions what to do?

UPDATE:

When I run my query, I see how memory of the system where database is running is increasing, while some scripts that are using database just "pause" working. When I stop SQL from running, everything works again. 

There are additional data:  #work_mem = 1MB (commented), shared_buffers = 32MB, 

index definition, table definition, SQL that is the issue: http://pastebin.com/4iMtpD4r

The database server is using the RAM, not the client application. This is the SQL with EXPLAIN (ANALYZE,BUFFERS) that executes in less than 1sec and do not cause problems. Same SQL, different UNIT in database (different ID) takes more than 15-30minutes: http://explain.depesz.com/s/OdqU.
The main problem is with the shared_buffers = 32MB parameter. It is 2014 not 2000. You cannot expect any kind of decent performance on a 6Gb machine, if you do not increase that to at least 512Mb. I believe that you are also using PostgreSQL 64bit (if not make the change now). Also, you say that your dataset = 1.5 GB. Are you sure? 50 million records fit on 1.5GB on disk? Have you run SELECT pg_database_size('myDbName'); Does it still show 1.5GB?

I also see you do not have an index at status_razsmernika field and you do a join on that, which leads to a sequential scan. You also have (razsmernik.status_razsmernika!=6) and (razsmernik.status_razsmernika !=0). So, you really need to add a b-tree index to status_razsmernika.

Also you are using the "updated" field for order in descending value. If this is always the case, specify the order in the related index as well. http://www.postgresql.org/docs/9.3/static/sql-createindex.html