Skip to content

Instantly share code, notes, and snippets.

View lesovsky's full-sized avatar
😉
Don't stop

Lesovsky Alexey lesovsky

😉
Don't stop
  • Postgres Pro
  • Yekaterinburg, Russian Federation
View GitHub Profile
@lesovsky
lesovsky / gist:3afe023b1843683adee6
Created September 11, 2014 17:43
insert_test_data.sql
drop function if exists insert_test_data(bigint,bigint,bigint);
create or replace function insert_test_data(bigint,bigint,bigint) returns void as $$
declare
seq_start bigint := $1;
seq_end bigint := $2;
interval constant bigint := $3;
step bigint := interval;
begin
while (seq_start - 1) != seq_end loop
insert into products select
@lesovsky
lesovsky / gist:ed4229fe6c4cbaeaf646
Last active August 29, 2015 14:06
delete_test_data.sql
create or replace function delete_test_data(chunk int,sleep int) returns void as $$
declare
chunk int := $1;
sleep_interval int := $2;
deleted_rows int;
begin
while dele
@lesovsky
lesovsky / pgbouncer-create-userlist.yml
Last active March 30, 2016 15:36
pgbouncer-create-userlist.yml
---
- hosts: all
vars:
userlist_file: /etc/pgbouncer/userlist.txt
userlist_owner: postgres
remote_user: root
tasks:
- name: "Stage 1: create temporary userlist.txt"
@lesovsky
lesovsky / ansible-postgresql94-bdr.yml
Created February 6, 2015 18:50
Install and setup PostgreSQL BDR with Ansible
---
- hosts: all
vars:
postgresql_datadir: /var/lib/pgsql/9.4-bdr/data
postgresql_upstream: 192.168.122.12
postgresql_downstream: 192.168.122.13
postgresql_bdr_database: bdrdemo
postgresql_admin_user: postgres
postgresql_shared_guc:
- { regexp: "^#?listen_addresses = .*$", guc: "listen_addresses = '*'" }
@lesovsky
lesovsky / postgresql-role-mgmt.yml
Created February 7, 2015 11:40
PostgreSQL role management with Ansible
---
- hosts: all
vars:
postgresql_roles:
- { rolname: "anovikov", privileges: "LOGIN,CREATEROLE,CREATEDB", password: "qwerty" }
- { rolname: "vpupkin", privileges: "LOGIN", password: "12345" }
remote_user: root
tasks:
@lesovsky
lesovsky / memtest.c
Created February 17, 2015 09:57
OOM reproduce
#include <stdio.h>
#include <stdlib.h>
int main (void) {
int n = 0;
while (1) {
if (malloc(1<<20) == NULL) {
printf("malloc failure after %d MiB\n", n);
return 0;
@lesovsky
lesovsky / mmap-simple-read-write.c
Last active August 29, 2015 14:24
Simple read/write to mmaped area.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#define DEFSZ 0x10000
static void *glob_var;
@lesovsky
lesovsky / mmap-write-locking-with-semaphore.c
Created July 7, 2015 17:04
Simple read/write on mmaped area with semaphore locks.
/*
* use -lpthread when build.
*/
#include <semaphore.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
@lesovsky
lesovsky / 2d-array-as-pointer.c
Created July 12, 2015 12:06
Passing 2d array as a pointer to function.
#include <stdio.h>
#include <stdlib.h>
void doit(int ** s , int row, int col)
{
int i, j;
for (i = 0; i < row; i++){
for (j = 0 ;j < col; j++)
printf("%d ", s[i][j]);
printf("\n");
}
@lesovsky
lesovsky / allocate-3d-array-storage.c
Created July 13, 2015 14:49
Create 3d array pointer and allocate space
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n_rows = 10, n_cols = 20, tup_size=64;
char ***z;
z = malloc(n_rows * sizeof(char **));
assert(z != NULL);