Skip to content

Instantly share code, notes, and snippets.

View cabecada's full-sized avatar

Vijaykumar Jain cabecada

View GitHub Profile
@cabecada
cabecada / gist:e9000dec167c831e315668757f56b479
Created March 26, 2024 10:32
playing with corruption postgres one file at a time
playing with corruption
initdb -D db1 --data-checksums 2>/dev/null >/dev/null
pg_ctl -D db1 -l db1.log start
psql <<EOF
create table t(col1 int primary key, col2 int);
create table t2(col1 int references t(col1) on update cascade on delete cascade);
insert into t select generate_series(1, 100);
insert into t2 select generate_series(1, 100);
EOF
https://www.postgresql.fastware.com/blog/how-to-fix-transaction-wraparound-in-postgresql
wget https://github.com/postgres/postgres/archive/697f8d266cfb33409f7ccf3319f4448477066329.zip
unzip 697f8d266cfb33409f7ccf3319f4448477066329.zip
cd postgresql-16
./configure --prefix /opt/16/usr/local --enable-tap-tests
cd /var/lib/postgresql/postgres/postgres-16/src/test/modules/xid_wraparound
make check PG_TEST_EXTRA='xid_wraparound'
postgres=# \d t1
Table "public.t1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
col1 | integer | | not null |
col2 | text | | |
Indexes:
"t1_pkey" PRIMARY KEY, btree (col1)
Referenced by:
TABLE "t2" CONSTRAINT "t2_col2_fkey" FOREIGN KEY (col2) REFERENCES t1(col1) ON UPDATE CASCADE ON DELETE CASCADE
@cabecada
cabecada / gist:e831c11011d28bd3347f2ee7e9fb14ee
Created March 16, 2024 14:24
citus migrate from pg14 worker to pg15 worker
postgres@pg:~/citusdb/migration/14$ /usr/lib/postgresql/14/bin/psql -p 5432 citusdb
psql (14.9 (Ubuntu 14.9-1.pgdg22.04+1), server 14.10 (Ubuntu 14.10-1.pgdg22.04+1))
Type "help" for help.
citusdb=#
citusdb=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------+-------+----------
public | dist_t | table | postgres
bloating system catalog to simulate slow systems
postgres@pg:~/udemy/15$ more db1/postgresql.auto.conf
# Do not edit this file manually!
# It will be overwritten by the ALTER SYSTEM command.
max_locks_per_transaction=512
allow_system_table_mods = on
failover testing citus
postgres@pg:~/citusdb$ cat setup.sh__
#!/bin/bash
export PATH=/opt/15/usr/local/bin:$PATH
port=5432
#coordinator
if [[ -d dbcr ]]
@cabecada
cabecada / gist:f188aa5d2d406861c4ffab6446c30945
Last active March 15, 2024 07:22
citus backup using pgbackrest and pitr restore using citus_create_restore_point
using citus_create_restore_point() for pitr
postgres@pg:~/citusdb/demo$ cat setup.sh
#!/bin/bash
export PATH=/opt/15/usr/local/bin:$PATH
port=5432
for i in db1 db2 db3
@cabecada
cabecada / gist:8024d98024559e9fc97ccfcb5324c09f
Last active March 12, 2024 19:20
corruption demo for blogs.
postgres@pg:~/udemy/16$ psql
psql (16.1 (Ubuntu 16.1-1.pgdg22.04+1))
Type "help" for help.
postgres=# drop table t;
DROP TABLE
postgres=# create table t(col1 text, col2 text);
CREATE TABLE
postgres=# insert into t select x::text, x::text from generate_series(1, 10) x;
INSERT 0 10
https://manishrjain.com/zfs-raid-ubuntu
@cabecada
cabecada / gist:7b7d2c306c41f35a9cfa96a0cafd6256
Created February 12, 2024 10:52
citus update view on distributed table
-- Create Employees table
CREATE TABLE Employees (
EmployeeID SERIAL PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Department VARCHAR(50),
Salary NUMERIC(10, 2)
);
CREATE TABLE Employees2 (