zlacker

[parent] [thread] 6 comments
1. truth_+(OP)[view] [source] 2021-06-12 13:29:17
While you are at it, don't forget to use UNLOGGED tables. UNLOGGED == In Memory.

But if you must use disk based table for Job queueing, set fillfactor = 50. This takes care of heavy updates.

Indexes are helpful but costs memory and CPU, so always make sure you partition the table based on job_type for performant pending job query.

I wouldn't recommend using LISTEN/NOTIFY unless you are okay with "at most once" semantics. I have used disk table based approach for PUB/SUB to replace Kafka. More fine tuned approach will also allow (job_type, consumer_group, publisher) as a partition key.

Ref - https://www.postgresql.org/docs/current/sql-createtable.html

replies(4): >>kureik+96 >>osigur+y9 >>Benoit+iq >>tpetry+CW
2. kureik+96[view] [source] 2021-06-12 14:27:19
>>truth_+(OP)
Thanks so much for this. I have been looking for this in Postgres. MySQL has memory back table which helped us a lot in the past.
3. osigur+y9[view] [source] 2021-06-12 15:01:36
>>truth_+(OP)
My understanding is, UNLOGGED means that changes are not written to the WAL and data can be lost in the event of an unscheduled shutdown. It doesn't mean that the table only exists in memory however - the data is still eventually persisted to disk.
replies(1): >>truth_+zb
◧◩
4. truth_+zb[view] [source] [discussion] 2021-06-12 15:17:52
>>osigur+y9
From the official doc link i shared already:

UNLOGGED

If specified, the table is created as an unlogged table. Data written to unlogged tables is not written to the write-ahead log (see Chapter 29), which makes them considerably faster than ordinary tables. However, they are not crash-safe: an unlogged table is automatically truncated after a crash or unclean shutdown. The contents of an unlogged table are also not replicated to standby servers. Any indexes created on an unlogged table are automatically unlogged as well.

replies(1): >>andrew+bd
◧◩◪
5. andrew+bd[view] [source] [discussion] 2021-06-12 15:34:05
>>truth_+zb
Uh, yeah, that confirms what osigurdson said, not that they're in-memory. For that IIRC you need to mount a ram-disk in your OS and put the table on that. Definitely also make it UNLOGGED, though.
6. Benoit+iq[view] [source] 2021-06-12 17:27:46
>>truth_+(OP)
I came here to post this. CREATE TABLE UNLOGGED is basically a redis in your postgres (with periodic dumps to disk), but with transactional joins into more persistent data.
7. tpetry+CW[view] [source] 2021-06-12 22:36:04
>>truth_+(OP)
Unlogged tables ARE NOT in memory tables. They are written to disk like every other table, but unlogged tables don‘t have use the wal and are therefore much lighter.
[go to top]