This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- For documentation on these functions, please see blog post at: | |
-- http://www.databasesoup.com/2012/10/determining-furthest-ahead-replica.html | |
-- determines current xlog location as a monotonically increasing numeric. | |
CREATE OR REPLACE FUNCTION xlog_location_numeric(vcloc text default NULL) | |
RETURNS numeric | |
LANGUAGE plpgsql | |
as $f$ | |
DECLARE cloc text; | |
floc text[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <libpq-fe.h> | |
#include <sys/time.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <string.h> | |
// channel to LISTEN on | |
const char *listenChannel = "foo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add the following to your base ResultSet class: | |
# fast row estimation function for postgres | |
# similar to ->count, but may be much faster for Pg < 9.2 | |
# uses query planner row count estimation, accuracy depends on when | |
# ANALYZE/autovacuum was last performed on the table | |
# more info: http://wiki.postgresql.org/wiki/Count_estimate | |
sub estimate_count { | |
my ($self) = @_; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Completely unused indexes: | |
SELECT relid::regclass as table, indexrelid::regclass as index | |
, pg_size_pretty(pg_relation_size(indexrelid)) | |
FROM pg_stat_user_indexes | |
JOIN pg_index | |
USING (indexrelid) | |
WHERE idx_scan = 0 | |
AND indisunique IS FALSE order by pg_relation_size(indexrelid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH btree_index_atts AS ( | |
SELECT nspname, relname, reltuples, relpages, indrelid, relam, | |
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum, | |
indexrelid as index_oid | |
FROM pg_index | |
JOIN pg_class ON pg_class.oid=pg_index.indexrelid | |
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace | |
JOIN pg_am ON pg_class.relam = pg_am.oid | |
WHERE pg_am.amname = 'btree' | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So, I did a quick test with pgbouncer running on the local host and talking to a remote postgresql backend. I had the script open a connection, run a quick almost instantaneous query (SELECT now() ), collect the results and close the connection. It looped over this 50,000 times. | |
Connecting to the bouncer over local unix socket, it took 31s to perform all the queries. | |
Connecting to the bouncer over localhost, it took 45s to perform all the queries. | |
Connecting to the bouncer running on the remote server, it took 1m6s | |
Without using pgbouncer, it took 3m34s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- function for doing dictionary-style replacement of varaibles | |
-- in a SQL string. variables are marked in the text with ${var} | |
-- and replaced using a json dictionary | |
create or replace function replace_vars ( somestring text, | |
vars JSON ) | |
returns text | |
language plpgsql | |
immutable | |
as |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# only supply or default logfile path when none is given explicitly in | |
# postgresql.conf | |
my @options = ($pg_ctl, 'start', '-D', $info{'pgdata'}); | |
my $logsize = 0; | |
if ($info{'logfile'}) { | |
push @options, ('-l', $info{'logfile'}); | |
# remember current size of the log | |
$logsize = (stat $info{'logfile'})[7] || 0; # ignore stat errors | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Result: 1 | |
Items { | |
TemplateId: "BADGE_BATTLE_ATTACK_WON" | |
Badge { | |
BadgeType: BADGE_BATTLE_ATTACK_WON | |
BadgeRanks: 4 | |
Targets: "\nd\350\007" | |
} | |
} | |
Items { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
const xhrProto = XMLHttpRequest.prototype, | |
origOpen = xhrProto.open, | |
origSend = xhrProto.send; | |
const typingUrlRegex = /https:\/\/discord.com\/api\/v6\/channels\/[0-9]+\/typing/; | |
xhrProto.open = function (method, url) { | |
this._url = url; | |
return origOpen.apply(this, arguments); |
OlderNewer