Skip to content

Instantly share code, notes, and snippets.

@cabecada
cabecada / gist:94fc1e1354dba8920e8bc5a96a7f6b10
Last active November 20, 2023 10:10
timezone lateral current time in all timezones
citusdb=# select * from pg_timezone_names limit 1;
name | abbrev | utc_offset | is_dst
------------+--------+------------+--------
Etc/GMT-12 | +12 | 12:00:00 | f
(1 row)
citusdb=# select current_timestamp at time zone 'UTC';
timezone
---------------------------
2023-11-20 09:59:05.33791
-- port 5432
drop publication db1 ;
drop subscription db12;
drop subscription db13;
drop table t;
create table t(id int primary key);
create publication db1 for all tables WITH ( PUBLISH = 'insert,update,delete,truncate' );
CREATE SUBSCRIPTION db12 connection 'dbname=postgres port=5433 host=localhost user=postgres' publication db2 WITH (origin = none, copy_data =
off);
CREATE SUBSCRIPTION db13 connection 'dbname=postgres port=5434 host=localhost user=postgres' publication db3 WITH (origin = none, copy_data =
@cabecada
cabecada / gist:51f6acff27dca16b0f5a5dbcf913c791
Created August 16, 2023 10:37
postgresql online column type change
why pg_repack will not do online data migration
https://github.com/reorg/pg_repack/pull/162
@cabecada
cabecada / gist:d03b7a75f380091d16672b36aedcd013
Last active August 15, 2023 18:43
citus failover testing
postgres@pg:~/citusdb$ cat setup.sh
#!/bin/bash
export PATH=/usr/lib/postgresql/14/bin:$PATH
port=5432
if [[ -d dbcr ]]
then
pg_ctl -D dbcr stop
rm -rf dbcr*
fi
@cabecada
cabecada / gist:95a6d4b4c3adbf4f350f96425c8bbda8
Created June 21, 2023 06:36
play with diff recovery options
https://blog.devgenius.io/setup-continuous-archiving-and-point-in-time-recovery-pitr-with-postgresql-db-7e670523e8e4
PostgreSQL is a powerful open-source relational database management system. It is widely used in various industries and applications due to its reliability, security, and scalability. One of its most useful features is Point-In-Time-Recovery (PITR), which allows you to recover your database to a specific point in time. PITR is essential in disaster recovery scenarios because it can minimize data loss.
Here are the steps to set up PITR with PostgreSQL:
Enable Archiving
In the postgresql.conf file, set the archive_mode configuration parameter to on. This will enable archiving.
Configure Archive Command
In the postgresql.conf file, set the archive_command configuration parameter to a command that will copy the WAL files to a safe location. For example, you can use the following command:
@cabecada
cabecada / gist:3e6352c6e2588aabc99faa7effc7b5ee
Created June 18, 2023 19:57
postmaster.pid file using chatgpt
i need to modify my postmaster.pid file in postgresql to a custom path. how to do it
ChatGPT
To modify the path of the postmaster.pid file in PostgreSQL, you'll need to update the configuration file (postgresql.conf) with the desired location. Here's a step-by-step guide to help you:
Locate the postgresql.conf file: The exact location of the file depends on your operating system and PostgreSQL installation. Common locations include:
Linux: /etc/postgresql/{version}/main/postgresql.conf
macOS: /usr/local/var/postgres/postgresql.conf
Windows: C:\Program Files\PostgreSQL\{version}\data\postgresql.conf
Open the postgresql.conf file using a text editor.
@cabecada
cabecada / Citus 11.1.md
Created April 14, 2023 14:11 — forked from hanefi/Citus 11.1.md
Generated Documentation of Citus using pg_readme

t

pg_extension_name: citus pg_extension_version: 11.1-1 pg_readme_generated_at: 2023-01-30 17:35:52.80893+03 pg_readme_version: 0.5.5

Citus distributed database

#if i bump number of concurrent subscriptions to 400 my vm freezes :), but otherwise it works fine. so may be some resource bottleneck
#is resulting in the errors
postgres@pg:~/temp$ cat run.sh
#!/bin/bash
for i in {1..3}
do
pg_ctl -D db$i -l db${i}.log stop
@cabecada
cabecada / gist:812de8362eaf4219452755cb3d9c50ae
Created March 17, 2023 09:25
pg_filenode.map global deleted and recovery
postgres@pg:~/temp$ initdb -D db1
postgres@pg:~/temp$ pg_ctl -D db1 -l db1.log start
waiting for server to start.... done
server started
postgres@pg:~/temp$
postgres@pg:~/temp$ pg_basebackup -D replica -R -c fast -C -S replica -d "port=5432"
postgres@pg:~/temp$ vim replica/postgresql.auto.conf
postgres@pg:~/temp$ pg_ctl -D db2 -l db2.log start
pg_ctl: directory "db2" does not exist
postgres@pg:~/temp$ pg_ctl -D replica -l replica.log start
@cabecada
cabecada / gist:6ff09966474dfdd2cd93bb479a3d86ec
Last active March 13, 2023 13:03
fun with citus extension
postgres@pg:~/citusdb$ more setup.sh
#!/bin/bash
export PATH=/usr/lib/postgresql/14/bin:$PATH
port=5432
for i in db1 db2 db3 db4
do
pg_ctl -D $i stop
rm -rf $i
initdb -D $i