Skip to content

Instantly share code, notes, and snippets.

#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
@cabecada
cabecada / gist:c67442c051404d1ff5548b40a0270398
Last active March 12, 2023 09:42
grouping by bucket size postgres
https://stackoverflow.com/questions/22157718/postgres-group-by-timestamp-into-6-hourly-buckets
select count(1), trunc(extract (minute from x) / 5) from generate_series(now() - '60 minute'::interval, now(), '1 minute'::interval) x group by trunc(extract (minute from x) / 5) order by 2 desc;
count | trunc
-------+-------
5 | 11
5 | 10
5 | 9
5 | 8
5 | 7
@cabecada
cabecada / gist:19cccfc762f6429860f6774f53a16e5c
Created February 24, 2023 13:59
postgresql trace app request to postgresql query in logs and pg_statement
how to generate a unique request id mapping to app request to a db query request.
i have a setup of
1) postgresql
2) flask app running on port 5000
3) haproxy running on port 8000 with backend as flask app. haproxy also generated a uuid header mapping app request to postgresql query.
```
postgres@pg:~$ cat /etc/haproxy/haproxy.cfg
global
@cabecada
cabecada / gist:36a89dc915758973e73f0514af9900eb
Created February 18, 2023 12:50
chatgpt and coredns 101
What is coredns
CoreDNS is an open-source Domain Name System (DNS) server software that can be used to provide DNS services for applications and services running in cloud-native environments. It is written in Go and is designed to be highly modular and extensible, allowing users to customize its functionality to suit their specific needs.
CoreDNS is often used as a replacement for traditional DNS servers like BIND, which can be difficult to configure and manage in cloud-native environments. CoreDNS supports a wide range of DNS features, including DNS-over-TLS, DNS-over-HTTPS, DNSSEC, and plugin-based customization of DNS functionality.
CoreDNS is used in many cloud-native platforms, including Kubernetes, which uses CoreDNS as its default DNS server. It can also be used as a standalone DNS server or as a component in larger cloud-native architectures.
what is consul from hashicorp
Consul is a tool for service discovery, configuration, and orchestration, developed by HashiCorp. It is an open-source solution that helps with managing distributed systems and microservices-based architectures.
Consul enables service discovery by maintaining a catalog of available services and their network locations. It also provides health checking capabilities to ensure that services are available and responsive. Additionally, Consul can be used to configure applications and services, as well as to manage and distribute secrets, such as API keys, passwords, and certificates.
Consul also includes a key-value store for storing and retrieving configuration data, and it supports distributed locking for coordination between multiple instances of a service. It also provides a built-in DNS server, allowing services to be discovered by name.
Consul is highly configurable and can be used in a variety of deployment scenarios, including on-premises, in the cloud, and in hybrid enviro
Vijaykumar Jain
What is redis
Redis (short for Remote Dictionary Server) is an open-source, in-memory data structure store that is commonly used as a database, cache, and message broker. It was created in 2009 by Salvatore Sanfilippo, and is often referred to as a key-value store, as it allows developers to store and retrieve data using keys and values.
Redis can store data structures such as strings, hashes, lists, sets, and sorted sets, and provides advanced features such as transactions, pub/sub messaging, Lua scripting, and support for multiple programming languages. Because Redis keeps data in memory, it can perform read and write operations very quickly, making it well-suited for use cases where high-performance and low latency are important, such as real-time applications.
Redis is popular in web applications and is used by many large companies like Twitter, GitHub, and Stack Overflow. Its ease of use, performance, and flexibility have made it a popular choice for a wide variety of use cases.
@cabecada
cabecada / gist:c413f528db046d9fc33c5cdadb54b433
Created February 4, 2023 07:25
qemu-virtualisation 101 with chatgpt
What is virtualisation
Virtualization is a technology that allows creating an abstraction layer on top of a physical server, network, or storage, allowing multiple virtual entities to run on the same physical hardware. This provides benefits such as increased utilization, reduced costs, improved scalability, and enhanced disaster recovery. There are different types of virtualization, including server virtualization, network virtualization, storage virtualization, and desktop virtualization.
Vijaykumar Jain
If I create two virtual machines, are they completed Isolated from each other
Yes, generally virtual machines are isolated from each other by default. They run on a virtualized environment, with each virtual machine having its own operating system, software, and applications, which are separate from those of other virtual machines. This provides the illusion of having multiple, independent systems running on a single physical machine, with each virtual machine operating as if it were a physical machine
@cabecada
cabecada / gist:51458e90f146c406badce4daaaafbc43
Created February 3, 2023 13:21
postgresql FEBE protocol and lifecycle of a connection
Vijaykumar Jain
what is the postgresql FEBE protocol
FEBE (Fast Execution of Batches in the Eventual Consistency Environment) is a protocol for executing multiple database commands in a single network round trip, as opposed to executing them one-by-one. It is specifically designed for databases like PostgreSQL, which support executing multiple commands in a single network round trip. The FEBE protocol can help reduce network overhead and improve performance in high-concurrency environments, where multiple clients are executing database commands simultaneously.
Vijaykumar Jain
what is the flow of packets when a simple select is fired from the client to postgresql server
When a client sends a simple "SELECT" statement to a PostgreSQL server, the following sequence of events takes place: