Skip to content

Instantly share code, notes, and snippets.

View ringerc's full-sized avatar

Craig Ringer ringerc

View GitHub Profile
BEGIN;
SET LOCAL bdr.skip_ddl_locking=on;
SET LOCAL bdr.skip_ddl_replication=on;
CREATE OR REPLACE FUNCTION public.simple_log_row()
RETURNS trigger LANGUAGE plpgsql
SET search_path = 'pg_catalog'
AS $$
BEGIN
@ringerc
ringerc / gist:d4a8fe97f5fd332d8b883d596d61e257
Created August 11, 2017 02:56
Failover slots with streaming rep proto
Phys rep Phys rep
using phys using
slot "B" phys slot "C"
+-------+ +--------+ +-------+
T | A <^--------+ B <---------+ C |
I | | | | | |
M +-------+ +--------+ +-------+
E | | |
| | | |CREATEs
| | | |logical slot X
From a7a69e8dc87504163222ba2570bda6920114a5c3 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@redacted>
Date: Sun, 26 Jun 2016 19:58:48 +0800
Subject: [PATCH] SPK utils build fixes
---
.gitignore | 4 ++++
src/SPK/File_IO.cpp | 2 ++
src/SPK/Makefile | 9 +++++----
src/SPK/String.h | 3 +++
@ringerc
ringerc / pg_elephant.c
Created May 18, 2016 13:16
pg_elephant()
#include "postgres.h"
#include "fmgr.h"
PG_MODULE_MAGIC;
PGDLLEXPORT Datum pg_elephant(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(pg_elephant);
static const char * const elephant =
"............MMMMMMMMMMM8..........MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM ...........\n"
@ringerc
ringerc / schema.sql
Created February 8, 2016 14:34
Demo Python script for replicating to Solr
CREATE TABLE book_lines
(
id serial primary key,
book_line text not null
);
@ringerc
ringerc / jpegify.py
Last active December 10, 2015 04:13
#!python
# coding=utf-8
#
# usage: python jpegify.py *.pdf
#
# Written for Python 2 or python 3
from __future__ import print_function
import os
@ringerc
ringerc / disconnect.py
Created October 3, 2015 13:40
Compare disconnect/reconnect and pooled times
#!/usr/bin/env python
#
# Disconnect/reconnect each query
#
# Takes 0.45s to run here
#
import time
import psycopg2
start_t = time.time()
From 0319a7ecbab5c1e85e300d93f674087786be144a Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Wed, 1 Apr 2015 10:46:29 +0800
Subject: [PATCH] pg_restore -t should select views, matviews, and foreign
tables
Currently pg_restore's '-t' option selects only tables, not other
relations. It should be able to match anything that behaves like
a relation in the relation namespace, anything that's interchangable
with a table, including:
@ringerc
ringerc / simple_spi_boilerplate.c
Last active September 9, 2021 04:06
SPI bgworker boilerplate
/* Simpler version that assumes there is no active tx or snapshot and SPI isn't connected yet */
const char * some_sql = "SELECT 1;";
/* setup */
Assert(!IsTransactionState());
StartTransactionCommand();
SetCurrentStatementStartTimestamp();
SPI_connect();
PushActiveSnapshot(GetTransactionSnapshot());
CREATE SCHEMA myschema;
CREATE TABLE myschema.zzafter(id integer);
CREATE OR REPLACE FUNCTION myschema.aabefore()
RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
somefield myschema.zzafter.id%TYPE;