Skip to content

Instantly share code, notes, and snippets.

View macdice's full-sized avatar

Thomas Munro macdice

View GitHub Profile
@macdice
macdice / pam-pg-hack.py
Created March 31, 2022 23:06
Quick example of using PAM for arbitrary external PostgreSQL authentication
#!/usr/bin/python3
#
# A dummy program that could be invoked by pam_exec.so, with the export_authtok
# option so that it sends the authtok to our stdin. This file needs to be
# executable (chmod +x).
#
# To make PostgreSQL use this for authentication via PAM, make sure that it is
# configured with --with-pam (apt-get install libpam-dev first), and then
# create a file /etc/pam.d/postgresql (or other chosen service name) that
# contains the following:
@macdice
macdice / batch.sql
Created November 21, 2019 02:55
Experimenting with batch and bucket functions
postgres=# create or replace function hash_combine(seed bigint, hash bigint)
returns bigint as
$$
select (seed # (hash + 2654435769 + (seed << 6) + (seed >> 2)))
& 4294967295;
$$ language sql;
CREATE FUNCTION
postgres=# create or replace function batch_by_rehash(nbatch int, nbucket int, hash bigint)
returns int as
$$
From bf72499bfecd4a6ea4757a445a2b711461639a56 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Fri, 15 Jun 2018 16:17:51 +1200
Subject: [PATCH] Experimental spinlock changes on amd64. Not tested.
Based on code review from mjg@freebsd.org, the LOCK prefix is redundant and
serves only to make the .text segment larger, and the fallback behaviour after
TAS() returns true should be to delay first, and then TAS_SPIN().
It may be that the logic in finish_spin_delay needs tweaking.
From 6e4025dc7d5a1f9866689e1e73b0bf2fe6b12dd7 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Fri, 1 Jun 2018 02:02:30 -0400
Subject: [PATCH] Add CI control files for Travis and AppVeyor.
This commit is not intended to be part of a patch submission, it's just a way
to trigger builds on Travis and/or AppVeyor. Push a PostgreSQL source tree
to GitHub including this commit, after enabling travis-ci.org and/or
appveyor.com to watch your GitHub repo and build any branch containing
.travis.yml/appveyor.yml.
#!/bin/sh
# pgbench -i -s 90
# psql postgres -c "create extension pg_prewarm"
PATH=~/install/bin:$PATH
export PATH
PGDATA=~/pgdata
CONF=$PGDATA/postgresql.conf
SECONDS=60
@macdice
macdice / test.c
Created May 8, 2018 02:39
POSIX_FADV_DONTNEED troubles
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#define BUFFER_SIZE 8192
int
From 8fd0b901f771b730159184890125ea0fc02a2261 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@enterprisedb.com>
Date: Thu, 12 Oct 2017 16:30:24 +1300
Subject: [PATCH] Example continuous integration control files.
This commit adds continuous integration control files. It shouldn't be
included in a patch submission, it's just for testing development branches.
https://wiki.postgresql.org/wiki/Continuous_Integration
---
diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c
index f5a45f1..50296f7 100644
--- a/sys/ufs/ffs/ffs_vnops.c
+++ b/sys/ufs/ffs/ffs_vnops.c
@@ -218,6 +218,29 @@ retry:
}
int
+ffs_sync_file_range(struct vnode *vp, off_t begin, size_t size)
+{
diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 96a64ce6b2c..ba0dcd3f15e 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -1559,7 +1559,6 @@ get_qual_for_range(PartitionKey key, PartitionBoundSpec *spec)
forboth(cell1, spec->lowerdatums, cell2, spec->upperdatums)
{
EState *estate;
- MemoryContext oldcxt;
Expr *test_expr;
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index 1e3ecbc..7958f9e 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -3083,7 +3083,7 @@ errorMissingColumn(ParseState *pstate,
errmsg("column %s.%s does not exist", relname, colname) :
errmsg("column \"%s\" does not exist", colname),
state->rfirst ? closestfirst ?
- errhint("Perhaps you meant to reference the column \"%s.%s\".",
+ errhint("Perhaps you meant to reference the column \"%s\".\"%s\".",