Skip to content

Instantly share code, notes, and snippets.

@keithf4
keithf4 / pg_partman--4.6.1--4.6.2.sql
Created May 11, 2022 16:08
Update to pg_partman 4.6.2
-- Fix bug introduced in verson 4.6.1 when pg_jobmon is installed and in use. Caused error to be raised around assignment of search_path variables. Thanks to @Dakotah312 on Github for reporting this issue (Github Issue #461).
CREATE OR REPLACE FUNCTION @extschema@.apply_constraints(p_parent_table text, p_child_table text DEFAULT NULL, p_analyze boolean DEFAULT FALSE, p_job_id bigint DEFAULT NULL) RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
ex_context text;
ex_detail text;
ex_hint text;
@keithf4
keithf4 / gist:904382cbb27c652e4e48b209e16a6603
Created November 4, 2021 15:09
Grafana 8.1.7 Value mapping
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
diff --git a/updates/pg_partman--4.4.0--4.5.0.sql b/updates/pg_partman--4.4.0--4.5.0.sql
index cacb056..135a96b 100644
--- a/updates/pg_partman--4.4.0--4.5.0.sql
+++ b/updates/pg_partman--4.4.0--4.5.0.sql
@@ -22,64 +22,74 @@
CREATE TEMP TABLE partman_preserve_privs_temp (statement text);
INSERT INTO partman_preserve_privs_temp
-SELECT 'GRANT EXECUTE ON FUNCTION @extschema@.create_sub_parent(text, text, text, text, text, text[], int, text, boolean, text, text, boolean, boolean) TO '||array_to_string(array_agg(grantee::text), ',')||';'
+SELECT 'GRANT EXECUTE ON FUNCTION @extschema@.create_sub_parent(text, text, text, text, text, text[], int, text, boolean, text, text, boolean, boolean) TO '||array_to_string(array_agg('"'||grantee::text||'"'), ',')||';'
@keithf4
keithf4 / gist:772eab64637b84b75427a7cf9ad4bcf9
Last active August 20, 2021 17:10
community.postgresql extension management

Our organization is still running Ansible 2.9 and we haven't made the full jump to collections and using Galaxy yet. So when testing the installation of PostgreSQL with PostGIS, we ran into this issue with the unpackaged extension version causing issues.

ansible-collections/community.general#1099

We saw that it has been fixed in the community.postgresql collection, but seeing how it was fixed is still a bit concerning for the long term. It is still trying to do a version comparison and, as far as PostgreSQL extensions are concerned, you cannot compare versions like this. This is because the version value and ordering is completely arbitrary, can be any valid alphanumeric value that PG can accept, and there really is no concept of one version being "greater" than another.

How PostgreSQL determines which version is installed and how you can upgrade from one to another is controlled entirely by the update files that an extension author provides. You give one version value followed b

@keithf4
keithf4 / pg_partman--4.3.0--4.3.1.sql
Last active April 13, 2020 18:45
pg_partman 4.3.1 update file
-- Add support for inheriting GENERATED columns from the parent table to the child tables. Thanks to @Dishwasha on Github for reporting the issue! (Github PR #302)
-- Fix handling of data existing in the default partition with time-based partitioning when that data is further ahead of any data that exists in non-default children. New child tables may not have been created as expected. Thanks to @adrianlzt on Github for reporting the issue! (Github Issue #303)
CREATE OR REPLACE FUNCTION @extschema@.create_partition_id(p_parent_table text, p_partition_ids bigint[], p_analyze boolean DEFAULT true, p_debug boolean DEFAULT false) RETURNS boolean
LANGUAGE plpgsql
AS $$
DECLARE
ex_context text;
ex_detail text;
#!/usr/bin/env python
# Script is maintained at https://github.com/keithf4/pg_bloat_check
import argparse, csv, json, psycopg2, re, sys
from psycopg2 import extras
from random import randint
version = "2.5.0"
$ sudo yum install icinga2
[...] | 2.5 kB 00:00:00
http://packages.icinga.com/epel/latest/release/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Application information:
Application version: r2.8.2-1
Installation root: /usr/local
Sysconf directory: /usr/local/etc
Run directory: /var/run
Local state directory: /var
Package data directory: /usr/local/share/icinga2
State path: /var/lib/icinga2/icinga2.state
Modified attributes path: /var/lib/icinga2/modified-attributes.conf
Objects path: /var/cache/icinga2/icinga2.debug
$ sudo icinga2 object list --type=Service --name=disk
Object 'www.example.com!disk' of type 'Service':
% declared in '/usr/local/etc/icinga2/zones.d/master/services.conf', lines 2:1-2:20
* __name = "www.example.com!disk"
* action_url = ""
* check_command = "disk"
% = modified in '/usr/local/etc/icinga2/zones.d/master/services.conf', lines 5:3-5:24
* check_interval = 60
% = modified in '/usr/local/etc/icinga2/conf.d/templates.conf', lines 28:3-28:21
* check_period = ""
@keithf4
keithf4 / file.md
Created February 20, 2018 19:11
VM Install

In preparation for this training session, a VirtualBox Image is available for download below (PGTraining_VM.zip). VirtualBox version 5.2 is required (5.2.6 as of this writing) as well as the Oracle VM VirtualBox Extension Pack, both of which can be downloaded from Oracle's website: https://www.virtualbox.org/wiki/Downloads

To import the VM, follow these steps:

  1. Extract the zip file (requires roughly 8GB)
  2. Open VirtualBox and go to the top menu: Machine -> Add...
  3. Browse to the extracted folder and select "PG Training - CentOS7.vbox"

You should be able to start the VM from there. With the extensions pack installed, bidirectional copy-n-paste should work. Snapshots are also available to reset the VM back to the original image.

https://www.joeconway.com/presentations/PGTraining_VM.zip