• 63 Posts
  • 676 Comments
Joined 2 年前
cake
Cake day: 2023年6月12日

help-circle



















  • Linux has kind of two forms of memory pages (entries in RAM), one is a file cache (page cache) and the other is “memory allocated by programs for work” (anonymous pages).

    When you look at memory consumed by a process you are looking at RSS, page/file cache is part of kernel and for example in btop corresponds to Cached.

    Page cache can never be moved into swap - that would be the same as duplicating the file from one place on a disk to another place on a (possibly different) disk.
    If more memory is needed, page cache is evicted (written back into the respective file, if changed). Only anonymous pages (not backed by anything permanent) can be moved into swap.

    So what does “PostgreSQL heavily relies on the OSs disk cache” mean? The more free memory there is, the more files can be kept cached in RAM and the faster postgres can then retrieve these files.

    When you add zram, you dedicate part of actual RAM to a compressed swap device which, as I said above, will never contain page cache.
    In theory this still increases the total available memory but in reality that is only true if you configure the kernel to aggressively “swap” anonymous pages into the zram backed swap.

    Notes: I tried to simplify this a bit so it might not be exact, also if you look at a process, the memory consumed by it is called RSS and it contains multiple different things not just memory directly allocated by the code of the program.


  • Had to solve the same problem few months ago, user provided content and so, user provided translations.
    We use postgres everywhere and we had to support 3 languages initially with one more eventually, so we decied to use json fields for anything that could be translated (which wasn’t too much). Mind you, this was basically a (temporarily permanent) prototype project but (fresh) postgres has a good support and operators for json so it worked alright.

    EDIT: I remembered that hstore might be a good alternative too, I think it was slightly less “heavy” and had better operators for the kind of access we needed