Skip to content

Instantly share code, notes, and snippets.

View macdice's full-sized avatar

Thomas Munro macdice

View GitHub Profile
tx1: BEGIN;
tx1: update ports dependency data
tx1: trigger sees row in cache_clearing_ports, decides not to insert new one
tx2: BEGIN;
tx2: sees row in cache_clearing_ports, deletes it
tx2: clears the cache
tx2: COMMIT;
external actor: doesn't see tx1, populates cache
diff --git a/configure b/configure
index 24655dc..e239641 100755
--- a/configure
+++ b/configure
@@ -10193,7 +10193,7 @@ fi
## Header files
##
-for ac_header in atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h pwd.h sys/epoll.h sys/ioctl.h sys/ipc.h sys/poll.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/socket.h sys/sockio.h sys/tas.h sys/time.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
+for ac_header in atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h pwd.h sys/epoll.h sys/event.h sys/ioctl.h sys/ipc.h sys/poll.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/socket.h sys/sockio.h sys/tas.h sys/time.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
postgres=# select application_name, replay_lag from pg_stat_replication order by application_name;
application_name | replay_lag
------------------+-----------------
node2 | 00:00:00.00323
node3 | 00:00:00.003447
node4 | 00:00:00.003464
node5 | 00:00:00.003607
node6 | 00:00:00.00351
node7 | 00:00:00.003494
node8 | 00:00:00.003403
# "Walrus"
#
# A quick and dirty hack to experiment with a kind of automatic query
# plan cache.
#
# This is not real code. It's entirely imaginary. But you could imagine
# turning it into a wrapper, a cursor factory, a mix-in, a shirt,
# a sock, a glove, a hat.
#
# Thought: types are going to suck with this transparent approach, right?
-- Demo of PostgreSQL 9.5 features for Wellington PostgreSQL User's Group
-- The following is not necessarily in the right order or exactly how I ran it,
-- I mixed it up a bit when presenting!
DROP TABLE IF EXISTS country CASCADE;
DROP TABLE IF EXISTS sales_per_person CASCADE;
DROP TABLE IF EXISTS film CASCADE;
macdice=> select * from a;
┌────┬──────┐
│ id │ name │
├────┼──────┤
│ 0 │ one │
└────┴──────┘
(1 row)
macdice=> select * from b;
┌────┬───────┬──────┐
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 325239d..2e18768 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -462,6 +462,11 @@ SyncRepReleaseWaiters(void)
walsndctl->lsn[SYNC_REP_WAIT_FLUSH] = MyWalSnd->flush;
numflush = SyncRepWakeQueue(false, SYNC_REP_WAIT_FLUSH);
}
+ if (walsndctl->lsn[SYNC_REP_WAIT_APPLY] < MyWalSnd->apply)
+ {
@macdice
macdice / gist:8e5b2f0fe3827fdf3d5a
Created June 16, 2015 22:05
slru-does-page-exist.patch
diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c
index 516a89f..ab85f6f 100644
--- a/src/backend/access/transam/multixact.c
+++ b/src/backend/access/transam/multixact.c
@@ -2734,7 +2734,7 @@ find_multixact_start(MultiXactId multi, MultiXactOffset *result)
pageno = MultiXactIdToOffsetPage(multi);
entryno = MultiXactIdToOffsetEntry(multi);
- if (!SimpleLruDoesPhysicalPageExist(MultiXactOffsetCtl, pageno))
+ if (!SimpleLruDoesPageExist(MultiXactOffsetCtl, pageno))
@macdice
macdice / gist:5f4b94acf563a609c962
Created May 14, 2015 23:31
Hierarchical tag system
CREATE TABLE tag (
id serial primary key,
name text not null,
parent integer references tag(id),
unique (parent, name)
);
CREATE TABLE photo (
id serial primary key,
path text not null
-- Midnight graph hacking with your host Thomas Munro <macdice+gist@penski.net>
create table data_source (
id serial primary key,
name text not null
);
create table currency (
id text primary key
);