Never add a column with default value, this locks the the entire table for updation. If you still want it to do , then do in batches based on timestamp.
When running queries in DB, specify lock_timeout
when running queries:
SET lock_timeout TO '2s';
ALTER TABLE items ADD COLUMN last_update timestampz;
Always create your indexes concurrently. Regular create index command blocks all writes for the duration of the command. While it doesn’t blocks SELECT
, this is still pretty bad and there’s better way:
CREATE INDEX CONCURRENTLY ...
It has a downside though, if something goes wrong then it doesn’t rollback and leaves behind an unfinished index. But Don’t worry you can drop it using:
DROP INDEX CONCURRENTLY ...
By default replication is Asynchronous and done via WAL
All Replica must use same Major Version
max_wal_senders → maximum wal sending processes
Wal_keep_segments → number of segments (16MB each) to keep , this is used to retain wal logs when network disconnects for replica