For some training purposes, I'd like to reproduce a bloated pg_wal directory so that I can show an example of what happens when Postgres
shuts down because of insufficient disk space.
So far I've tried feeding psql
the ouptut of the following bash script :
#!/bin/sh
for i in {1..100}; do
echo "create table temp_$i (id text);" >> bloat_wals.sql
for j in {1..1000}; do
echo "insert into temp_$i values('`cat /dev/urandom | tr -dc '[:alpha:]' | fold -w ${1:-20} | head -n 1`');" >> bloat_wals.sql
done
echo "drop table temp_$i;" >> bloat_wals.sql
done
which generates the following sql file bloat_wals.sql
:
create table temp_1 (id text);
insert into temp_1 values('KRzMmncvZzjZlbLTNtQd');
insert into temp_1 values('haXsbsFOUfavkUNeLTSP');
insert into temp_1 values('LYVhfMlWRnfVnhPIvYtb');
...
drop table temp_1;
create table temp_2 (id text);
insert into temp_2 values('qKqRjlCqUddycHENZrQJ');
insert into temp_2 values('SeztNglqJQfWICoyZeCs');
insert into temp_2 values('cgKVcTteWGZXWEHrqTqa');
drop table temp_2;
create table temp_3 (id text);
insert into temp_3 values('OPuidYENyZWfIlsehSvS');
insert into temp_3 values('ZYakjYKzkbwAkjBksKBi');
insert into temp_3 values('oUUBHKMZQeMQejJyvaZL');
...
insert into temp_100 values('SeztNglqJQfWICoyZeCs');
insert into temp_100 values('cgKVcTteWGZXWEHrqTqa');
drop table temp_100;
But this is not increasing the size of the pg_wal
directory significantly.
From reading about Postgres wal configuration documentation, it looks like the following parameters/functions could be used to achieve this :
- checkpoint_timeout
- max_wal_size
- pg_switch_wal ()
- archive_command=/bin/true
Please let me know what would be the easiest way to bloat a pg_wal directory ? I'm using a raw database so any suggestion is welcome.